Giter Site home page Giter Site logo

Comments (7)

tkahn avatar tkahn commented on September 21, 2024

Your code in the first example should work. Do you have an example page?
Also, you should end the method call with a semicolon:

$("#makeMeScrollable").smoothDivScroll("startAutoScrolling");

but I don't think it has anything to do with this error.

from smooth-div-scroll.

marcelo2605 avatar marcelo2605 commented on September 21, 2024

Hello Thomas. Thanks for the reply!

Here is a test page with what I'm trying to do:

http://www.pratadesign.com.br/exemplos/

The problem is that after some use, the scroll stops working correctly.

from smooth-div-scroll.

tkahn avatar tkahn commented on September 21, 2024

I think that at least part of problem has to do with with keeping the internal state of the plugin in sync with the toggle button. Consider this:

  1. The plugin is autscrolling.
  2. The user moves the mouse over one of the hot spots. What happens (internally) is that Smooth Div Scroll stops the autoscrolling.
  3. Now you have a button that says "pause" to stop the auto scrolling, but since it has already been stopped clicking the button once won't do anything. You will have to click it twice to start the scrolling again. This is due to the toggle setting of the button.

To fix this you should rewrite the button code so instead of being just a toggle button it has to know if the scroller is running or not and change states after this. One way to accomplish this is to use the callbacks autoScrollingStopped and autoScrollingStarted.

Good luck!

from smooth-div-scroll.

marcelo2605 avatar marcelo2605 commented on September 21, 2024

Hi Thomas,

I'm doing exactly that. See how's the code:

$("#makeMeScrollable").smoothDivScroll({autoScrollingStopped: function(eventObj, data) {
                $('#btn').text('play');
                $('#btn').click(function(){
                    $("#makeMeScrollable").smoothDivScroll("startAutoScrolling")
                });
            }});            

            $("#makeMeScrollable").smoothDivScroll({autoScrollingStarted: function(eventObj, data) {
                $('#btn').text('pause');
                $('#btn').click(function(){
                    $("#makeMeScrollable").smoothDivScroll("stopAutoScrolling")
                });
            }});            

It works for a while, but then the page starts to be slow and the play / pause button failure

from smooth-div-scroll.

tkahn avatar tkahn commented on September 21, 2024

Hmm, it sounds like you get some sort of memory leak or circular reference. The code in the latest example is not okay since you are initializing Smooth Div Scroll twice. Will this work? I just wrote down the code in a text editor but I can't test it:

var scrolling = true;

var Stopped = function(eventObj, data) {
    $('#btn').text('play');
    scrolling = false;
}

var Started = function(eventObj, data) {
    $('#btn').text('pause');
    scrolling = true;
}

$("#makeMeScrollable").smoothDivScroll({
    autoScrollingStopped: Stopped,
    autoScrollingStarted: Started
});

$('#btn').click(function(){
    if(scrolling) {
        $("#makeMeScrollable").smoothDivScroll("stopAutoScrolling");
    } else {
        $("#makeMeScrollable").smoothDivScroll("startAutoScrolling")
    }
});

When seing how you use the plugin, an idea would be to provide a public method for getting the current status of the plugin. In its simplest form it could be isAutoScrolling that returned true or false. It could also be more advanced and return a JSON object with all kinds of status codes. There is one such method today (getScrollerOffset).

from smooth-div-scroll.

marcelo2605 avatar marcelo2605 commented on September 21, 2024

Thanks Thomas. Now ist's works.

from smooth-div-scroll.

tkahn avatar tkahn commented on September 21, 2024

Okay! Glad it worked out for you. I'm closing this issue now.

from smooth-div-scroll.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.