You will recieve your password to this address. Address is not made public.

Your preferred username that is used when logging in.

How do I stop auto-scoll after user interaction? Created Nov 10, 2009

This thread is solved

Views: 1432     Replies: 2     Last reply Sep 11, 2010  
You must login first before you can use this feature

BrendanHargie

Posts: 1

Registered:
Nov 10, 2009

How do I stop auto-scoll after user interaction?

Posted: Nov 10, 2009

I was wondering if anyone could help me. I have the scrollable auto-scrolling through a series of images, but I want to be able to stop this once a user clicks either the prev or next buttons. At this moment, it keeps continuing until it reaches the last image, then stops.

Any help with this would be greatly appreciated.

Cheers.

Brendan

Dave
sparkfire.net

Posts: 5

Registered:
Nov 18, 2009

» How do I stop auto-scoll after user interaction?

Posted: Nov 18, 2009

Reply to: How do I stop auto-scoll after user interaction?, from BrendanHargie
I actually had to do something similar with a project and was delighted to find the jquery tools scrollable plugin. Like you though, I had a autoscrolling feature, but it had to stop upon any user interaction (let the user navigation through the panels on their own), and to carry it one step further, after a given amount of inactivity, continue the autoscrolling. The given time limits might be: 10 seconds per panel, with auto resume happening after 30 seconds of inactivity, but I'm using smaller values so that it is easier to debug.

What you want to accomplish can be done through the api property. You construct an event listener on the panel (or anything else) for a click perhaps, and on click, call api.pause(); To take it further again, I'm using a javascript timeout which calls api.play() in a given time frame, if the user does not click again (you must also be sure to clear out any old timouts before refreshing with a new one.

I'm using all of the plugins which aren't really necessary, the key things you want to follow are the variables at the top for setting time limits, the fact that I'm catching the return value from .scrollable() into window.api, and then referencing it below in the click event listener. Hope this helps, good luck!

The code follows:


// execute your scripts when the DOM is ready. this is a good habit 
$(document).ready(function() {
     
    var hovertime = 3; // time in seconds to stay on each panel
    var idletime = 10; // time in seconds that user is idle before cycle begins again
    var idletimer = 0; // store our idle timer id so we can keep refreshing it
    
    // initialize scrollable, setup plugins and params
    window.api = $("div.scrollable").scrollable({
                                                 size:1
                                                })
                                    .circular()
                                    .navigator()
                                    .autoscroll({
                                                 steps: 1,
                                                 interval: hovertime*1000,
                                                 autopause: false,
                                                 api: true
                                                });
    
    // if the user clicks the panel
    $('div.scrollable').click(function() {
        // pause the autoplay to let them navigate manually
        api.pause();
        
        // everytime they click we want to refresh our timer, so we must delete the old one
        if (idletimer) {window.clearTimeout(idletimer);}
        
        // set a timer which will return the panel to autoplay after no activity
        idletimer = window.setTimeout(function() {
            api.play();
        }, idletime*1000);
    
    });
}); 

Shadowsong

Posts: 36

Registered:
Sep 11, 2010

» » How do I stop auto-scoll after user interaction?

Posted: Sep 11, 2010

Reply to: » How do I stop auto-scoll after user interaction?, from sophistihip
Thanks for the code Dave! :) Is this topic solved? I guess so. :/