因为临时要重构老项目,将jsp文件写成html文件,于是就发现了有蛮多的bug。

首先,因为jsp中有include方法,但是html中没有,所以只能暂时用iframe来代替,但是iframe的坑也有很多,今天遇到一个关于滚动条的问题,即点击下一页接受数据后自动滚到顶部,自己查了很多资料说用。

var scroll_top =window.parent.document.documentElement.scrollTop;来获取,但是我自己用的时候总是为0,无奈只能只能自己打印window.parent慢慢搜索。

终于在window.parent.document.scrollingElement中发现了scrollTop。

function totop() {
      var scroll_top = window.parent.document.scrollingElement;
      $(scroll_top).animate({
        scrollTop : '0px'
      }, 400);
}

  这样就可以直接在iframe中将页面滚到顶部了

 posted on 2017-07-24 18:10  Yhspehy  阅读(864)  评论(0编辑  收藏  举报