Skip to content
Permalink
Browse files

Position demo: Address todo comment by replacing plugin methods

  • Loading branch information
jzaefferer committed Apr 24, 2014
1 parent 62c9a9c commit 16f421fd50c8c9df7c45f75c3bf75ad0aeca515e
Showing with 21 additions and 22 deletions.
  1. +21 −22 demos/position/cycler.html
@@ -25,52 +25,51 @@
</style>
<script>
$(function() {
// TODO refactor into a widget and get rid of these plugin methods
$.fn.left = function( using ) {
return this.position({
function left( element, using ) {
element.position({
my: "right middle",
at: "left+25 middle",
of: "#container",
collision: "none",
using: using
});
};
$.fn.right = function( using ) {
return this.position({
}
function right( element, using ) {
element.position({
my: "left middle",
at: "right-25 middle",
of: "#container",
collision: "none",
using: using
});
};
$.fn.center = function( using ) {
return this.position({
}
function center( element, using ) {
element.position({
my: "center middle",
at: "center middle",
of: "#container",
using: using
});
};
}

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

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

$( window ).resize(function() {
$( "img:eq(0)" ).left( animate );
$( "img:eq(1)" ).center( animate );
$( "img:eq(2)" ).right( animate );
left( $( "img:eq(0)" ), animate );
center( $( "img:eq(1)" ), animate );
right( $( "img:eq(2)" ), animate );
});
});
</script>

0 comments on commit 16f421f

Please sign in to comment.
You can’t perform that action at this time.