JavaScript how to make div move left to right faster? make mouse move left to right,make parabola move left

I want the div to move left to right on scroll. Which I did.

But, how do I make the div go to the right much faster? Because the speed of the div going from left to right is the same as the scrollbar's speed going from top to bottom. Sorry if I'm not making any sense to you.

Here's the JSFiddle - https://jsfiddle.net/wx8d0a1x/

$(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
    });
});
});
Answer:1

Just add a multiplier to

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

see fiddle: https://jsfiddle.net/DIRTY_SMITH/wx8d0a1x/1/

Answer:2

Right now your speed depends on the length of the document. If you want it to reach the right side by the halfway point in your document, multiply your scrollpercent by 2. If you want it to reach the right by a quarter of the way use a multiplier of 4.. etc..

Use Math.min() to ensure that the box doesn't scroll off page.

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

    $(window).scroll(function () {
        var s = $(this).scrollTop(),
            d = $(document).height(),
            c = $(this).height(),
            m = 2; //Speed multiplier

        scrollPercent = Math.min((s / (d - c)*m),1);

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

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

I have this custom jQuery function : jQuery.fn.extend({ disable: function () { return $(this).each(function () { // function code }); } }); When I do something ...

I have this custom jQuery function : jQuery.fn.extend({ disable: function () { return $(this).each(function () { // function code }); } }); When I do something ...

  1. jquery working with json
  2. jquery working with arrays
  3. jquery working with cookies
  4. jquery working with xml
  5. jquery working with forms
  6. jquery working with this
  7. jquery not working with bootstrap
  8. jquery not working with updatepanel
  9. jquery not working with ajax loaded content
  10. jquery not working with angularjs
  11. jquery not working with dynamic content
  12. jquery not working with vue
  13. jquery not working with react
  14. jquery not working with angular
  15. jquery not working with vuejs
  16. jquery not working with ie 11
  17. jquery not working with appended elements
  18. jquery not working with angular 6
  19. jquery not working with ie
  20. jquery not working with django

When using fullscreen image gallery and blending between pictures, some images are much bigger and takes some time to load and show up. Yes, there is a function called onload which is called when ...

When using fullscreen image gallery and blending between pictures, some images are much bigger and takes some time to load and show up. Yes, there is a function called onload which is called when ...

  1. information when there
  2. is there any information when the applicant graduated

Can nested HTML list items be forced to be aligned to the left? for eg: Bat Cat Ratonetwothree Mat <ul> <li>Bat</li> <li>Cat</li> <li>...

Can nested HTML list items be forced to be aligned to the left? for eg: Bat Cat Ratonetwothree Mat <ul> <li>Bat</li> <li>Cat</li> <li>...

  1. nested html list
  2. html nested list example
  3. html nested list generator
  4. nested list html css
  5. html nested list items
  6. html nested list numbering
  7. nested list html w3schools
  8. nested list html code
  9. html nested list not indenting
  10. html nested list style
  11. nested list html program
  12. nested list html bootstrap
  13. html nested list indent
  14. html nested list without bullets
  15. html nested list exercises
  16. nested list html definition
  17. html nested list roman numerals
  18. nested list html questions
  19. html nested list not working
  20. nested list html 1.1

I have following markup for my nav-menu and menu icon to toggle it. <a href="#navigation" class="toggle-menu">&#9776;</a> <nav id="navigation"> <a href="#" class="nav-...

I have following markup for my nav-menu and menu icon to toggle it. <a href="#navigation" class="toggle-menu">&#9776;</a> <nav id="navigation"> <a href="#" class="nav-...