jQuery scrolltop firefox not working

北城以北 提交于 2019-11-26 06:48:10

问题


This script:

function onscroll(){
    document.getElementById(\"divs\").style.top=\"\"+$(\'body\').scrollTop()+\"px\";
}

Fiddle: http://jsfiddle.net/Hed2J/1/

Doesn\'t work on the latest Firefox version!

What am I doing wrong? :) Thanks for the help!

Edit: Edited with JSFiddle and full script :) as attached to an onscroll event


回答1:


Try this fiddle, it is working in chrome, ie and the latest version of mozilla : http://jsfiddle.net/Hed2J/3/

I replace $('body').scrollTop() with $(window).scrollTop().




回答2:


A little off-topic, but if you want to animate using scrolltop, you must do

$('html,body').animate({scrollTop:0}, 'slow');

Note that we target both html and body because html will make scroll in Firefox works and body for other browsers.



来源:https://stackoverflow.com/questions/17776544/jquery-scrolltop-firefox-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!