Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the scroll speed using css or jQuery?

Tags:

jquery

css

scroll

In the example below, I would like to reduce the scroll speed of the div's content, especially when using the mouse wheel, as one wheel tick scrolls approximately the div's height.

Is it possible to control that with CSS, and if not, javascript (perhaps using jQuery) ?

.scrollable {      width: 500px;      height: 70px;      overflow: auto;   }
<div class="scrollable">      Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?  </div>

Note: I realize that the scroll speed might differ between os/browers and browser settings. But I think that in the majority of the cases, the scroll speed (when using the mouse wheel) is too fast, so I would like to slow it down.

like image 772
Benjamin Crouzier Avatar asked Sep 13 '11 20:09

Benjamin Crouzier


People also ask

How do I scroll faster?

Scroll one page at a time in all major browsers including Microsoft Internet Explorer and Mozilla Firefox by pressing the Spacebar key. Move back up the page by pressing Shift + Spacebar or the Home key on the keyboard.

How do you handle a scroll in CSS?

The scroll-behavior property specifies whether to smoothly animate the scroll position, instead of a straight jump, when the user clicks on a link within a scrollable box.

Is scroll a CSS?

The scroll-behavior property in CSS allows us to define whether the scroll location of the browser jumps to a new location or smoothly animates the transition when a user clicks a link that targets an anchored position within a scrolling box.


1 Answers

The scroll speed CAN be changed, adjusted, reversed, all of the above - via javascript (or a js library such as jQuery).

WHY would you want to do this? Parallax is just one of the reasons. I have no idea why anyone would argue against doing so -- the same negative arguments can be made against hiding DIVs, sliding elements up/down, etc. Websites are always a combination of technical functionality and UX design -- a good designer can use almost any technical capability to improve UX. That is what makes him/her good.

Toni Almeida of Portugal created a brilliant demo, reproduced below:

jsFiddle Demo

HTML:

<div id="myDiv">     Use the mouse wheel (not the scroll bar) to scroll this DIV. You will see that the scroll eventually slows down, and then stops. <span class="boldit">Use the mouse wheel (not the scroll bar) to scroll this DIV. You will see that the scroll eventually slows down, and then stops. </span> </div> 

javascript/jQuery:

  function wheel(event) {       var delta = 0;       if (event.wheelDelta) {(delta = event.wheelDelta / 120);}       else if (event.detail) {(delta = -event.detail / 3);}        handle(delta);       if (event.preventDefault) {(event.preventDefault());}       event.returnValue = false;   }    function handle(delta) {       var time = 1000;       var distance = 300;        $('html, body').stop().animate({           scrollTop: $(window).scrollTop() - (distance * delta)       }, time );   }    if (window.addEventListener) {window.addEventListener('DOMMouseScroll', wheel, false);}     window.onmousewheel = document.onmousewheel = wheel; 

Source:

How to change default scrollspeed,scrollamount,scrollinertia of a webpage

like image 87
cssyphus Avatar answered Nov 08 '22 00:11

cssyphus