|
17 | 17 | </style>
|
18 | 18 | <script>
|
19 | 19 | $(function() {
|
| 20 | + // TODO refactor into a widget and get rid of these plugin methods |
20 | 21 | $.fn.position2 = function( options ) {
|
21 | 22 | return this.position( $.extend({
|
22 | 23 | of: window,
|
|
54 | 55 | });
|
55 | 56 | };
|
56 | 57 |
|
57 |
| - $( "img:eq(0)" ).left(); |
58 |
| - $( "img:eq(1)" ).center(); |
59 |
| - $( "img:eq(2)" ).right(); |
60 |
| - |
61 | 58 | $( "body" ).css({
|
62 | 59 | overflow: "hidden"
|
63 | 60 | })
|
|
68 | 65 | position: "absolute",
|
69 | 66 | });
|
70 | 67 |
|
| 68 | + $( "img:eq(0)" ).left(); |
| 69 | + $( "img:eq(1)" ).center(); |
| 70 | + $( "img:eq(2)" ).right(); |
| 71 | + |
71 | 72 | function animate( to ) {
|
72 |
| - $(this).animate( to ); |
| 73 | + $(this).stop( true, false ).animate( to ); |
73 | 74 | }
|
74 |
| - function next() { |
| 75 | + function next( event ) { |
| 76 | + event.preventDefault(); |
75 | 77 | $( "img:eq(2)" ).center( animate );
|
76 | 78 | $( "img:eq(1)" ).left( animate )
|
77 | 79 | $( "img:eq(0)" ).right().appendTo( ".demo" );
|
78 | 80 | }
|
79 |
| - function previous() { |
| 81 | + function previous( event ) { |
| 82 | + event.preventDefault(); |
80 | 83 | $( "img:eq(0)" ).center( animate );
|
81 | 84 | $( "img:eq(1)" ).right( animate );
|
82 | 85 | $( "img:eq(2)" ).left().prependTo( ".demo" );
|
83 | 86 | }
|
84 | 87 | $( "#previous" ).click( previous );
|
85 | 88 | $( "#next" ).click( next );
|
86 | 89 |
|
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 ); |
89 | 92 | });
|
90 | 93 |
|
91 | 94 | $( window ).resize(function() {
|
|
100 | 103 |
|
101 | 104 | <div class="demo">
|
102 | 105 |
|
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" /> |
106 | 109 |
|
107 | 110 | <a id="previous" href="#">Previous</a>
|
108 | 111 | <a id="next" href="#">Next</a>
|
|
0 commit comments