DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > jQuery - Auto Scrolling the Slider

jQuery - Auto Scrolling the Slider

Dave Bush user avatar by
Dave Bush
·
Mar. 23, 09 · Web Dev Zone · News
Like (0)
Save
Tweet
18.16K Views

Join the DZone community and get the full member experience.

Join For Free
Question from Yuhsin:

I would like to make the jquery steps slider to do auto-increment when the window loads. Is there an easy way to trigger the slide to move by itself ?

I’m assuming this question is looking for the content to auto scroll as well.  So, let’s pull up the code from last week and take a look at this issue.

There is a timer plugin available for jQuery that will do some of the work for you, but all we really need for this functionality is:

  • A function to do the auto incrementing
  • A call to the javascript setTimeout() function.

So first, the auto incrementing function.

function scrollWindow() {

var slideValue;
slideValue = $("#slider").slider("value");
if(slideValue > -100)
{
$("#slider").slider("value", slideValue - 1);
setTimeout(scrollWindow, 1000);
}
}

A couple things to note about this function:

  • We are retrieving the current position of the slider using the .slider() method of the slider widget.
  • We are assuming that the range of our slider is between 0 and -100.
  • We call setTimeout at the end to call this function again in a second.
  • We only call setTimeout if we have not reached the end of our scrolling.

The only thing left is that we need to kick this off when the page loads.  To do this we add a call to setTimeout in our jQuery ready method:

$(function() {
$("#slider").slider(
{ change: handleChange,
slide: handleSlide,
min: -100,
max: 0
});
setTimeout(scrollWindow, 1000);
});

The actually scrolling of the window happens “automatically” with the code we wrote last week.

 

JQuery

Published at DZone with permission of Dave Bush, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Data Lakes, Warehouses and Lakehouses. Which is Best?
  • Debugging Deadlocks and Race Conditions
  • Three Mantras for Effective Standup Meetings
  • Python: A Befitting Approach to Develop AI Web Apps

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo