jQuery scrolltop firefox not working

前端 未结 2 1101
鱼传尺愫
鱼传尺愫 2020-11-27 08:09

This script:

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

Fiddle: http://jsf

相关标签:
2条回答
  • 2020-11-27 08:55

    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().

    0 讨论(0)
  • 2020-11-27 08:55

    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.

    0 讨论(0)
提交回复
热议问题