How to change CSS when user scrolls specific div

I am trying to implement a scroll function that moves elements based on where the user scrolls, this code still works and it moves the elements.

The thing is, I want to have a list of different functions that move certain elements whenever you scroll past a specific div based on its id or class.

I thought that if I changed $("#pagelight2").scrollTop(), it would work, but it did not help

Any guidance would be appreciated.

thank

The updated code works, but it really is buggy every time I watch the animation, it stops moving - does anyone know a more efficient way to make this work?

    var $scrollingDiv = $(".Page3-PeopleWalkingDown");

    var p = $("#pagedark3");

    var offset = p.offset();

    var top = offset.top;

    $(window).scroll(function() {

                var scrollval = $(window).scrollTop() - top;

                if ($(window).scrollTop() > 1400) {
                    $scrollingDiv
                        .stop()
                        .animate({
                            "left": "-" + (scrollval) + "px"
                        });

                } else


                {

                    $scrollingDiv
                        .stop()
                        .animate({
                            "left": +(0) + "px"
                        });
                }
+4
6

, DIV .

, .scroll(), (.. "div" "" ), .

, ( (, div offset -600px) "reset" , , . , .

offset: http://api.jquery.com/offset/

scrollTop: http://api.jquery.com/scrolltop/

+9

Skrollr CSS ( / div) .

, div, , , div .

var s = skrollr.init();
<script src="http://prinzhorn.imtqy.com/skrollr/dist/skrollr.min.js"></script>

<div style="height: 100px"></div>
<div data-0p="background-color: red;" data-100="background-color: !green;" style="height: 200px;background-color: red;" >
</div>
Hide result
+5

https://github.com/customd/jquery-visible

jQuery, , , . , true. , , .

, , , ..

+3

, jquery , , , . .

. : http://jsfiddle.net/xgmbf5ro/3/

$(window).scroll(function() {
    var offset = $(self).offset();
    var distance = parseInt(offset.top) - parseInt($(window).scrollTop());
    var l = (distance / parseInt($(self).outerHeight())) * 100;

    if (l > 0) {
        l = "0";
    }

    $(self).css("left", l+"%");
});

, , DOM, . left . .animate(), !

jQuery, div, : $("#myDiv").slideOut();.

, .

+3

All Articles