Skip to content

Slider: animation of range and handle in sync #1530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/unit/slider/slider_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ test( "mouse based interaction", function() {
.simulate( "drag", { dx: 10, dy: 10 } );

});

asyncTest( "range slider animation", function() {
expect( 2 );

var animateDuration = 2000,
element = $( "#slider1" )
.slider({
range: "max",
animate: animateDuration,
min: 0,
max: 100,
value: 0
}),
handle = element.find( ".ui-slider-handle" ),
highlight = element.find( ".ui-slider-range" ),
left = element.offset().left,
width = element.width();

element.simulate( "mousedown", { clientX: left + width });
element.simulate( "mouseup" );

setTimeout(function () {
element.simulate( "mousedown", { clientX: left } );
element.simulate( "mouseup" );
equal( highlight.width(), 0, "animation of range in sync" );
ok( Math.abs( handle.offset().left ) > Math.abs( left + width ), "animation of handle in sync" );
start();
}, animateDuration / 2);
});

test( "keyboard based interaction", function() {
expect( 3 );

Expand Down
25 changes: 20 additions & 5 deletions tests/visual/slider/range_slider.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@ <h3>When set both values of range slider to the maximum, slider should not lock<
<br>
<button id="set-max-values">set values to max</button>
<button id="set-min-values">set values to min</button>
<br><br>

<hr>

<h1>Max Range Slider</h1>
<h3>Animation of range and handle in sync</h3>
<div id="max-slider"></div>
</div>

<script>
var el = $( "#slider" ).slider({
range: true,
min: 0,
max: 100,
values: [ 0, 50 ]
});
range: true,
min: 0,
max: 100,
values: [ 0, 50 ]
}),
el2 = $( "#max-slider" ).slider({
range: "max",
animate: "slow",
min: 0,
max: 100,
values: 50
});

//range slider
$( "#set-max-values" ).on( "click", function() {
el.slider( "option", { values: [ 100, 100 ] } );
});
Expand Down
4 changes: 2 additions & 2 deletions ui/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
}
if ( oRange === "max" && this.orientation === "horizontal" ) {
this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, o.animate );
}
if ( oRange === "min" && this.orientation === "vertical" ) {
this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
}
if ( oRange === "max" && this.orientation === "vertical" ) {
this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, o.animate );
}
}
},
Expand Down