为了账号安全,请及时绑定邮箱和手机立即绑定

jQuery从不同页面滚动到ID

jQuery从不同页面滚动到ID

森林海 2019-09-21 11:21:03
我试图在某些页面中使用jQuery的页面滚动,并且可以成功地进行平滑的页面滚动。我现在唯一的问题是尝试从其他页面执行此操作。我的意思是,如果我单击页面中的链接,它将加载新页面,然后滚动到特定的div元素。这是我用来在页面内滚动的代码:var jump=function(e){       //prevent the "normal" behaviour which would be a "hard" jump       e.preventDefault();   //Get the target   var target = $(this).attr("href");   //perform animated scrolling   $('html,body').animate(   {           //get top-position of target-element and set it as scroll target           scrollTop: $(target).offset().top   //scrolldelay: 2 seconds   },2000,function()   {           //attach the hash (#jumptarget) to the pageurl           location.hash = target;   });}$(document).ready(function(){       $('a[href*=#]').bind("click", jump);       return false;});我希望这个主意很清楚。谢谢非常重要的注意:我上面发布的这段代码在同一页面内也很好用,但是我要单击的是单击一个页面上的链接,然后转到另一页面,然后滚动到目标。我希望现在已经清楚了。谢谢
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 404 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信