如何防止在jQuery中自动滚动到顶部
How do I prevent auto-scrolling to the top in jQuery?
这适用于所有其他浏览器,我不知道问题出在哪里。我有点赶时间,所以我想我会问你们,以防我错过了任何明显的东西。我有一个链接,你点击它会启动一个弹出窗口,在Firefox(可能还有opera)中,页面会自动滚动回顶部。
$('[class*=popup-link]').click(function(e) {
/* Prevent default actions */
e.preventDefault();
e.stopPropagation();
/* Get the id (the number appended to the end of the classes) */
var name = $(this).attr('class');
var id = name[name.length - 1];
/* Show the correct popup box, show the blackout and disable scrolling */
$('#popup-box-'+id).show();
$('#blackout').show();
$("html,body").css("overflow","hidden");
});
我需要preventDefault和stopPropagation来阻止其他事情的发生。你能看到任何错误或停止自动滚动到顶部的方法吗?谢谢
快速编辑:
我还在运行一个功能,使用将盒子居中
$(window).scroll(centerBox);
我不确定这是否会以某种奇怪的方式影响firefox中的滚动。这个函数的内容只是添加CSS,所以我怀疑它们会对它产生任何影响
另一个编辑:
一个尝试的链接。对我来说,不能在Firefox中工作。http://inserthtml.com/demo/internal-popup/
首先,我在脚本中没有看到任何错误。即使只有CCD_ 1,它也应该防止"顶部跳跃"。试着把它简化为这个。它应该判断这个处理程序是否导致
$('[class*=popup-link]').click(function(e) {
e.preventDefault(); //prevent the click from jumping esp on hashes
e.stopPropagation(); //prevent from any parent click handlers that didn't prevent the jump
//no code here for now
return false; //the natural way to prevent the jump
});
如果这段代码阻止了跳转,那么代码的其余部分会导致跳转,尤其是脚本损坏。检查控制台是否也有错误
e.preventDefault();
e.stopPropagation();
相当于
return false;
更改它们,您就可以完成
相关文章:
- 滚动固定滚动顶部()的跳跃效果
- 当偏移量改变时滚动顶部
- 滚动顶部在滑动后不起作用切换
- 使滚动顶部始终检查
- 页面滚动在粘性页脚布局中保持滚动顶部位置
- 滚动顶部闪烁-Internet Explorer
- j查询滚动顶部麻烦
- 我如何使用滚动顶部()获取HTML文档的位置
- 滚动顶部到元素 - 20px
- JQuery 偏移和滚动顶部问题
- 滚动事件仅在滚动顶部时触发
- 单击并滚动顶部
- 每次在顶部滚动顶部重置
- IE <选择>滚动顶部
- 打开对话框正在更改我的滚动顶部位置
- 为什么有时滚动顶部/滚动左不可写
- 滚动顶部 Jquery
- 数据表在页面更改时滚动顶部
- 使用滚动顶部显示滚动的像素
- 可以 jQuery invalidHandler 通过父窗口中的 iframe 滚动顶部