jQuery-slimScroll icon indicating copy to clipboard operation
jQuery-slimScroll copied to clipboard

Scroll doesn't work until the mouse is moved

Open alvarotrigo opened this issue 10 years ago • 18 comments

I'm creating slimScroll structure dynamically as well as calling the initialization.

I've been able to reproduce the problem in a jsfiddle with a timeout so you can have time to place the mouse over the scrolling div, and without moving it at all, try to scroll. This will show the bug. Slimscroll won't scroll unless you move the mouse.

http://jsfiddle.net/u9P87/9/

Why there's a mousemove event inside the mousedown here?

    bar.bind("mousedown", function(e) {
            var $doc = $(document);
            isDragg = true;
            t = parseFloat(bar.css('top'));
            pageY = e.pageY;

            //why is this here?
            $doc.bind("mousemove.slimscroll", function(e){

alvarotrigo avatar May 16 '14 09:05 alvarotrigo

Nothing? No ideas why?

alvarotrigo avatar May 28 '14 15:05 alvarotrigo

The problem you described does not seem to have anything to do with this particular line of code. The problem was still present after commenting out the mousemove event.

freddyamsterdam avatar Jun 04 '14 09:06 freddyamsterdam

@freddyamsterdam yeah right.

I detected the cause of it. It is entering in the following condition:

function _onWheel(e)
        {
          // use mouse wheel only when mouse is over
          if (!isOverPanel) { return; }

alvarotrigo avatar Jun 04 '14 09:06 alvarotrigo

I see... me.hover() is not fired unless the mouse is moved... This is how it works... I will try to figure something out or just set the isOverPanel to true for my own purposes.

alvarotrigo avatar Jun 04 '14 10:06 alvarotrigo

You beat me to it, I was just typing the same thing!

Probably has to do with the fact that jQuery .hover() is combination of mouseenter and mouseleave.

freddyamsterdam avatar Jun 04 '14 10:06 freddyamsterdam

    // show on parent mouseover
    me.hover(function(){
      isOverPanel = true;
      showBar();
    }, function(){
      isOverPanel = false;
      hideBar();
    });

    me.on('mouseover', function(){
      isOverPanel = true;
      showBar();                
    })
    me.on('mouseout', function(){
      isOverPanel = false;
      hideBar();                
    })  

freddyamsterdam avatar Jun 04 '14 10:06 freddyamsterdam

That doesn't solve the problem. I already tried it.

I ended up deleting the if (!isOverPanel) { return; } from the _onWheel function. Not quite sure why is it there...

alvarotrigo avatar Jun 04 '14 10:06 alvarotrigo

Sweet! Works like a charm.

freddyamsterdam avatar Jun 04 '14 10:06 freddyamsterdam

But it causes another problem... not a proper solution.

Anyone solved this issue??

alvarotrigo avatar Nov 10 '14 12:11 alvarotrigo

So from everything I've seen, knowing the mouse position on page load isn't possible. It is explained well here: http://stackoverflow.com/questions/8013062/how-to-track-mouse-position-from-on-page-load-as-well-as-on-mouse-move

Removing if (!isOverPanel) { return; } hijacks scrolling for the entire page. In my case I have a vertical menu in a fixed drawer (similar to http://designcouch.com/demos/pure-css-drawer-menu.html). If there are more menu items than can fit in the browser window, overflow: auto; should allow for scrolling within the drawer. Without the isOverPanel check, any scrolling outside of the context of a slimScroll region doesn't work.

I did find this fairly hacky solution that relies on a CSS background color that would seem to work http://stackoverflow.com/questions/6586166/detect-mouse-hover-on-page-load-with-jquery.

jnettik avatar Feb 19 '15 23:02 jnettik

@jnettik well done! Have you integrated it with fullPage.js already?

alvarotrigo avatar Feb 20 '15 16:02 alvarotrigo

Not yet. I should have some time later today to test it and get a PR out.

jnettik avatar Feb 20 '15 20:02 jnettik

That's great. Have you submited it as a pull request for this plugin (slimScroll)? It would be nice to have it in the official version as well.

alvarotrigo avatar Feb 20 '15 22:02 alvarotrigo

I haven't . Not sure how I'd get it to work with the plugin. It doesn't have any CSS to add the background-color: transparent; to. Since the class names for the plugin are configurable, I don't know what I could tie any styles to anyway. It works with your plugin because the .fp-scrollable class doesn't change.

The best idea I have is to add the javascript that detects the background color, and add some documentation for people using the plugin to add the style themselves. Or an example, as the documentation seems to be outside GitHub.

I'm open to other ideas if someone has them though.

jnettik avatar Feb 20 '15 23:02 jnettik

@alvarotrigo What is the 'other problem' that removing the line "if (!isOverPanel) { return; } " causes? I've removed that line with no problems!

magentapose avatar Apr 01 '15 09:04 magentapose

Solved by using:

setTimeout(function () {
    $('.text').wrapInner('<div class="scrollable" />');

    $('.text').find('.scrollable').slimScroll({
        height: '250px',
        alwaysVisible: true,
        size: '10px'
    });

    //HERE!
    $('.text').find('.scrollable').mouseover();    
}, 2000);

Online demo

alvarotrigo avatar May 01 '15 10:05 alvarotrigo

👍

jssuttles avatar Apr 13 '17 16:04 jssuttles