Skip to content

Commit d945d29

Browse files
jzaeffererscottgonzalez
authored andcommitted
Position: Fix initial positioning of cycler demo.
(cherry picked from commit 8f71acc)
1 parent a24aa8d commit d945d29

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

demos/position/cycler.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</style>
1818
<script>
1919
$(function() {
20+
// TODO refactor into a widget and get rid of these plugin methods
2021
$.fn.position2 = function( options ) {
2122
return this.position( $.extend({
2223
of: window,
@@ -54,10 +55,6 @@
5455
});
5556
};
5657

57-
$( "img:eq(0)" ).left();
58-
$( "img:eq(1)" ).center();
59-
$( "img:eq(2)" ).right();
60-
6158
$( "body" ).css({
6259
overflow: "hidden"
6360
})
@@ -68,24 +65,30 @@
6865
position: "absolute",
6966
});
7067

68+
$( "img:eq(0)" ).left();
69+
$( "img:eq(1)" ).center();
70+
$( "img:eq(2)" ).right();
71+
7172
function animate( to ) {
72-
$(this).animate( to );
73+
$(this).stop( true, false ).animate( to );
7374
}
74-
function next() {
75+
function next( event ) {
76+
event.preventDefault();
7577
$( "img:eq(2)" ).center( animate );
7678
$( "img:eq(1)" ).left( animate )
7779
$( "img:eq(0)" ).right().appendTo( ".demo" );
7880
}
79-
function previous() {
81+
function previous( event ) {
82+
event.preventDefault();
8083
$( "img:eq(0)" ).center( animate );
8184
$( "img:eq(1)" ).right( animate );
8285
$( "img:eq(2)" ).left().prependTo( ".demo" );
8386
}
8487
$( "#previous" ).click( previous );
8588
$( "#next" ).click( next );
8689

87-
$( ".demo img" ).click(function() {
88-
$( ".demo img" ).index( this ) === 0 ? previous() : next();
90+
$( ".demo img" ).click(function( event ) {
91+
$( ".demo img" ).index( this ) === 0 ? previous( event ) : next( event );
8992
});
9093

9194
$( window ).resize(function() {
@@ -100,9 +103,9 @@
100103

101104
<div class="demo">
102105

103-
<img src="images/earth.jpg" />
104-
<img src="images/flight.jpg" />
105-
<img src="images/rocket.jpg" />
106+
<img src="images/earth.jpg" width="458" height="308" />
107+
<img src="images/flight.jpg" width="512" height="307" />
108+
<img src="images/rocket.jpg" width="300" height="353" />
106109

107110
<a id="previous" href="#">Previous</a>
108111
<a id="next" href="#">Next</a>

0 commit comments

Comments
 (0)