Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2013, 12:23 PM   PM User | #1
jonnystudent
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jonnystudent is an unknown quantity at this point
Animate jquery ui slider handle to specific value on pageload

I'm having problems getting a slider to animate to a certain value. The value is within the handle. I want the handle to automatically move on pageload to a specific value. The value has to increment up to the value though.

I've created a script in where I'm animating the handle but I can't get the values to increment accordingly. Here is my current script.

Slider1:

Code:
$("#slider1").slider({
    max:350,
    min:100,
    step:10,
    value:100,
    animate: 'true',
	animate: 6000,
    slide: function(event, ui) {  
        $("#amount").val(ui.value);
        $(this).find('.ui-slider-handle').html('<div class="sliderControl-label v-labelCurrent">£'+ui.value+'</div>');
        
                update();
       
    } ,
    change :function(event, ui) {  
        $("#amount").val(ui.value);
        $(this).find('.ui-slider-handle').html('<div class="sliderControl-label v-labelCurrent">£'+ui.value+'</div>');
        
                update();       
    } 
});
$("#slider1").slider("value", 200);
update();
On page load, the value should start at 100 and then automatically increment in 10's up to 200. Although, 200 just appears.

Any help would be greatly appreciated. Cheers.
jonnystudent is offline   Reply With Quote
Old 01-31-2013, 07:40 PM   PM User | #2
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 356
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
Can you please provide a full example, preferably a "working" version on jsfiddle? I just tried setting this up and besides update() not being defined and it looking not exactly nice – I do see the animation from 100 to 200.
Airblader is offline   Reply With Quote
Old 01-31-2013, 11:36 PM   PM User | #3
jonnystudent
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jonnystudent is an unknown quantity at this point
Quote:
Originally Posted by Airblader View Post
Can you please provide a full example, preferably a "working" version on jsfiddle? I just tried setting this up and besides update() not being defined and it looking not exactly nice – I do see the animation from 100 to 200.
Hi Airblader, the handle animates fine. It's the value in the handle which I want to animate to go from 100 to 200 in increments of 10. Here is a fiddle: http://jsfiddle.net/vNf9K/

Thanks,

Jonny

Last edited by jonnystudent; 01-31-2013 at 11:42 PM..
jonnystudent is offline   Reply With Quote
Old 02-01-2013, 09:09 AM   PM User | #4
jonnystudent
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jonnystudent is an unknown quantity at this point
Ok, I got this to work, although the animation isn't smooth.

Code:
$("#slider1").slider({
    max:350,
    min:100,
    step:10,
    value:100,
    slide: function(event, ui) {  
        $("#amount").val(ui.value);
        $(this).find('.ui-slider-handle').html('<div class="sliderControl-label v-labelCurrent">£'+ui.value+'</div>');
        
       
    } ,
    change :function(event, ui) {  
        $("#amount").val(ui.value);
        $(this).find('.ui-slider-handle').html('<div class="sliderControl-label v-labelCurrent">£'+ui.value+'</div>');
        
    } 
});
var val = 100;
var timer = setInterval(function() {
    if (val <= 200) {
        $("#slider1").slider("value", val);
        val += 10;
    }
    else {
        clearInterval(timer);
    }
}, 200);
It would be highly appreciated if anyone can make the animation smooth.

Cheers,

Jonny
jonnystudent is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:39 AM.


Advertisement
Log in to turn off these ads.