question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to replicate 'stepless' scrolling on mousedown of non button element?

See original GitHub issue

Hello,

I want to achieve the stepless scrolling behaviour that occurs when holding down an up or down button, but on non button elements, eg something like:

$(document).on("mousedown", ".up", function() {
$('#scrollable_content').mCustomScrollbar('scrollTo','+=100');
});

$(document).on("mousedown", ".down", function() {
$('#scrollable_content').mCustomScrollbar('scrollTo','-=100');
});  

This issue (https://github.com/malihu/malihu-custom-scrollbar-plugin/issues/248) provides a solution to achieve it when scrollbuttons has enable: true.

But how do I achieve this behaviour when scrollbuttons are not enabled?

The desired behaviour is like that achieved with the following settings:

scrollButtons:{ 
enable: true,
scrollType:"stepless",
scrollAmount:"auto"
}

Thank You.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
malihucommented, Feb 14, 2015

Hi,

You can do it with some extra jquery code. I’m posting a (working) code example below (it’s a bit compact but commented)

var el=$("#content-1"), // set the element with the scrollbar
    duration=3000, // set a base duration/speed of the buttons scrolling
    timer,content;

// scrollbar initialization 
// add the necessary callbacks to your fn call (no need to modify the callback functions)

el.mCustomScrollbar({
    // callbacks needed for scrolling buttons calculations
    callbacks:{
        onInit:function(){ content=this.mcs.content },
        whileScrolling:function(){ timer=duration*this.mcs.topPct/100; }
    }
});

// scrolling buttons functions (assumes your buttons are .up and .down) 
// no need to change anything here unless your buttons have different classes/selectors

$(document).on("mousedown mouseup",".down,.up",function(e){
    var to,speed,on=e.type==="mousedown" ? 1 : 0,
        cpos=content[0].offsetTop;
    if($(this).is(".down")){ // down
        to=on ? "bottom" : cpos;
        speed=on ? (timer ? duration-timer : duration) : 0;
    }else{ // up
        to=on ? "top" : cpos;
        speed=on ? timer : 0;
    }
    el.mCustomScrollbar("stop").mCustomScrollbar("scrollTo",to,{
        scrollInertia:speed,scrollEasing:"linear",timeout:0
    });
}).on("click",".down,.up",function(e){
    e.preventDefault();
});

Hope this helps

0reactions
vishalp36commented, Mar 28, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to scroll div continuously on mousedown event?
How to continuously scroll '#items' until user releases the button? I tried using jquery mousedown event and animate function but couldn't make it...
Read more >
Element.scroll() - Web APIs - MDN Web Docs
Chrome Edge scroll Full support. Chrome61. Toggle history Full support. Edge79. T... options.behavior parameter Full support. Chrome61. Toggle history Full support. Edge79. T... options.left parameter Full...
Read more >
Smooth Scrolling | CSS-Tricks
Accessibility of Smooth Scrolling​​ The page may scroll, but the scrolling is a side effect of the focus changing. If you override the...
Read more >
Creating Custom Scrollbars with React - This Dot Labs
The scrollbar div will contain a button to scroll up, the elements of the thumb and track inside a wrapper div , and...
Read more >
Introduction to browser events - The Modern JavaScript Tutorial
An event is a signal that something has happened. All DOM nodes generate such signals (but events are not limited to DOM).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found