Bar*_*urg 2 html javascript mobile jquery mobile-browser
我不想实现的是按下按钮时滚动到某个位置的页面.我在Chrome和IE等浏览器上工作,但似乎无法在任何移动浏览器上运行.
这是我使用的代码:
$("#programmaMenu").on("click", "div", function(event){
event.preventDefault();
$('html').stop().animate({
scrollTop: $("#"+$(this).attr("rel")).position().top - 120
}, 500, 'swing');
});
Run Code Online (Sandbox Code Playgroud)
该事件触发,只有滚动不会发生.
感谢用户vohuman,这就是答案:
显然,移动浏览器滚动body元素,桌面浏览器滚动html元素.因此,问题的解决方案是选择元素'html'和'body',如下所示:
$("#programmaMenu").on("click", "div", function(event){
event.preventDefault();
$('html, body').stop().animate({
scrollTop: $("#"+$(this).attr("rel")).position().top - 120
}, 500, 'swing');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7114 次 |
| 最近记录: |