I have a basic "scroll to top" jQuery function for use on my site. This function works as I would like in Chrome, Opera, and IE though not in my Firefox (37.0.2).
我有一个基本的“滚动到顶部”jQuery函数在我的网站上使用。这个功能可以像Chrome,Opera和IE一样运行,但不在我的Firefox(37.0.2)中。
The function is as follows:
功能如下:
function scrollUp(){
$("#to-top").hide();
$(window).bind('mousewheel', function(){
var num = $(window).scrollTop();
if (num > 100){
$("#to-top").show(500);
};
if (num < 100){
$("#to-top").hide();
};
$("#to-top").click(function(){
$("#to-top").hide();
$('body,html').stop().animate({scrollTop:0},1200);
});
});
}
scrollUp();
I have checked the inspect element boxes in Firefox but no errors are appearing.
我检查了Firefox中的inspect元素框,但没有出现错误。
For this to work the HTML is:
为此,HTML是:
<a id="to-top">
<center><p>^ ^ ^</p><p>Scroll To Top</p></center>
</a>
<script src="../scripts/toTop.js">scrollUp()</script>
located at the bottom of the page before the closing body tag.
位于关闭正文标记之前的页面底部。
The HTML is not showing anything in firefox which means that the first line of the jQ function must be working, though for some reason after that it doesn't.
HTML没有在firefox中显示任何内容,这意味着jQ函数的第一行必须正常工作,尽管由于某些原因它没有。
I originally had .on() instead of .bind() they functioned the same in the other browsers buy not firefox....
我原来有.on()而不是.bind()他们在其他浏览器中运行相同而不是firefox ....
Any help is appreciated, thanks guys!
任何帮助表示赞赏,谢谢你!
1 个解决方案
#1
1
Use the scroll
event and bind using .on
使用scroll事件并使用.on绑定
$(document).on('scroll', function () { /* your mousewheel code here */ });
If memory serves, Firefox doesn't like the mousewheel
event. I'm pretty sure the scroll
event should work though.
如果内存服务,Firefox不喜欢mousewheel事件。我很确定滚动事件应该可以工作。
Also, you don't need to run $(window).bind
every time you scrollUp()
. That only needs to be done on $(document).ready
此外,每次scrollUp()时都不需要运行$(window).bind。这只需要在$(document).ready上完成
#1
1
Use the scroll
event and bind using .on
使用scroll事件并使用.on绑定
$(document).on('scroll', function () { /* your mousewheel code here */ });
If memory serves, Firefox doesn't like the mousewheel
event. I'm pretty sure the scroll
event should work though.
如果内存服务,Firefox不喜欢mousewheel事件。我很确定滚动事件应该可以工作。
Also, you don't need to run $(window).bind
every time you scrollUp()
. That only needs to be done on $(document).ready
此外,每次scrollUp()时都不需要运行$(window).bind。这只需要在$(document).ready上完成