Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery scrolltop firefox not working

Tags:

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

like image 613
seanlevan Avatar asked Jul 21 '13 20:07

seanlevan


2 Answers

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

like image 173
Lucas Willems Avatar answered Oct 20 '22 21:10

Lucas Willems


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.

like image 41
Thanh Trung Avatar answered Oct 20 '22 21:10

Thanh Trung