Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do something when page is scrolling and have some position

i have a little problem with page scrolling... I wanna to change some css when i'm scrolling page down and if window have 100px from top position... This is my code. Much thx for help.

$(document).ready(function(){
    $(window).scroll(function(){
        if ($(window).scroll(100)){
            $('.ufo').css('right','800px');
        }
    });
});
like image 724
Lukas Avatar asked Jun 12 '12 10:06

Lukas


People also ask

How do I make DIVS stay in one place when scrolling?

Use position fixed. Position fixed makes it so that an element stays at it's specified place even if the user scrolls up or down.

How do I scroll to a specific position in HTML?

window. scrollTo( value-x, value-y ); Here value-x is the pixel value of the width, where you wanna jump or scroll to. value-y is for the height of the window in terms of the pixel where you wanna jump or scroll to.

Which position will keep the element in the same place regardless of scrolling?

An element with position:fixed is fixed with respect to the viewport. It stays where it is, even if the document is scrolled.


1 Answers

Try this:

$(document).ready(function(){
    $(window).scroll(function(){
        if ($(window).scrollTop() > 100){
            $('.ufo').css('right','800px');
        }
    });
});
like image 153
gdoron is supporting Monica Avatar answered Oct 06 '22 19:10

gdoron is supporting Monica