layui问题之自动滚动二级iframe页面到指定位置

一、问题

前提:用的layui框架
目标:改变iframe页面滚动条位置
问题:没有麻溜溜的滚。。

二、经过

刚开始,以为只要滚动iframe里面的元素就行了,页面所有元素都在section里面,就通过section使滚动条滚动
    $('section.layui-larry-box').scrollTop(300);
可想而知,不行
然后,又试了div啥的
最后直接试了包含这个页面的iframe标签,让iframe滚动
    $(this).children('iframe').scrollTop(300);
不行。。

三、解决

最后看了一下原生js使iframe滚动的方法
    document.getElementById('ghrzFrame').contentWindow.scrollTop=50;
感觉jq也要加一个类似contentWindow功能的函数
结果:
    $(this).children('iframe').contents().scrollTop(300);

猜你喜欢

转载自blog.csdn.net/yan263364/article/details/79290535