Skip to content

Commit

Permalink
Position: Fix initial positioning of cycler demo.
Browse files Browse the repository at this point in the history
(cherry picked from commit 8f71acc)
  • Loading branch information
jzaefferer authored and scottgonzalez committed Jul 20, 2012
1 parent a24aa8d commit d945d29
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions demos/position/cycler.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</style>
<script>
$(function() {
// TODO refactor into a widget and get rid of these plugin methods
$.fn.position2 = function( options ) {
return this.position( $.extend({
of: window,
Expand Down Expand Up @@ -54,10 +55,6 @@
});
};

$( "img:eq(0)" ).left();
$( "img:eq(1)" ).center();
$( "img:eq(2)" ).right();

$( "body" ).css({
overflow: "hidden"
})
Expand All @@ -68,24 +65,30 @@
position: "absolute",
});

$( "img:eq(0)" ).left();
$( "img:eq(1)" ).center();
$( "img:eq(2)" ).right();

function animate( to ) {
$(this).animate( to );
$(this).stop( true, false ).animate( to );
}
function next() {
function next( event ) {
event.preventDefault();
$( "img:eq(2)" ).center( animate );
$( "img:eq(1)" ).left( animate )
$( "img:eq(0)" ).right().appendTo( ".demo" );
}
function previous() {
function previous( event ) {
event.preventDefault();
$( "img:eq(0)" ).center( animate );
$( "img:eq(1)" ).right( animate );
$( "img:eq(2)" ).left().prependTo( ".demo" );
}
$( "#previous" ).click( previous );
$( "#next" ).click( next );

$( ".demo img" ).click(function() {
$( ".demo img" ).index( this ) === 0 ? previous() : next();
$( ".demo img" ).click(function( event ) {
$( ".demo img" ).index( this ) === 0 ? previous( event ) : next( event );
});

$( window ).resize(function() {
Expand All @@ -100,9 +103,9 @@

<div class="demo">

<img src="images/earth.jpg" />
<img src="images/flight.jpg" />
<img src="images/rocket.jpg" />
<img src="images/earth.jpg" width="458" height="308" />
<img src="images/flight.jpg" width="512" height="307" />
<img src="images/rocket.jpg" width="300" height="353" />

<a id="previous" href="#">Previous</a>
<a id="next" href="#">Next</a>
Expand Down

0 comments on commit d945d29

Please sign in to comment.