Luuk Teulings
Luuk Teulings

Reputation: 3

How can I increase the scrollspeed of the div?

I am trying to make a sort of parallax webdesign. My question is, if someone knows how I can make the red div move faster. I think its in the formule but dont know sure. Maybe someone knows?

Here is my code: http://jsfiddle.net/PvVdq/

$(document).ready(function () {
var $horizontal = $('#horizontal');

$(window).scroll(function () {
    var s = $(this).scrollTop(),
        d = $(document).height(),
        c = $(this).height();

    scrollPercent = (s / (d - c));

    var position = (scrollPercent * ($(document).width() - $horizontal.width()));

    $horizontal.css({
        'left': position
    });
});

});

Upvotes: 0

Views: 145

Answers (2)

Emad Dehnavi
Emad Dehnavi

Reputation: 3441

Yuo need to play with your scrollPercent , if you want it go faster :

    scrollPercent = (s / (d - c) * 2);//twice fatser

or even faster :

    scrollPercent = (s / (d - c) * 3);//3 times fatser

http://jsfiddle.net/PvVdq/1448/

Upvotes: 0

Pro_Newbie
Pro_Newbie

Reputation: 118

I'm not so sure about this. When I tried this one, it speeds up the movement of the red div

$(document).ready(function () {
var $horizontal = $('#horizontal');

$(window).scroll(function () {
    var s = $(this).scrollTop(),
        d = $(document).height(),
        c = $(this).height();

    scrollPercent = (s / (d - c));

    var position = (scrollPercent * 10 * ($(document).width() - $horizontal.width()));

    $horizontal.css({
        'left': position
    });
});
});

Upvotes: 1

Related Questions