jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 105 ] Chapter 5 width:295px; margin:0 auto; padding:0; list-style-type:none; } #slider ul:after { content:"."; visibility:hidden; display:block; height:0; clear:both; } #slider li { margin-right:10px; float:left; } #prev, #next { position:absolute; top:175px; } #prev { left:20px; } #next { position:absolute; right:10px; } .hidden { display:none; } #slide { width:2000px; height:300px; position:absolute; top:0; left:0; } #slide img { float:left; } #title { margin:0; text-align:center; } 5. Save this in the css folder as animate-position.css, and don't forget to link to the new stylesheet from the of our page. Run the page in your browser now, before we get into the scripting, so that you can see how the widget behaves without the accompanying script. You should find that any image can be viewed by clicking its corresponding link using only CSS, and this will work in any browser. The previous and next arrows are hidden with our CSS because these will simply not work with JS turned off and the image titles are not displayed, but the widget's core functionality is still fully accessible. What just happened? The underlying HTML in this example is very straightforward. We have an outer container for the content-viewer as a whole, then within this we have a container for our content panels (simple images in this example) and a navigation structure to allow the different panels to be viewed. Some of the elements we've added style rules for in our CSS file aren't hardcoded into the underlying markup, but will be created as necessary when needed. Doing it this way ensures that the content-viewer is still usable even when the visitor has JavaScript disabled. One important point to note is that the #slide wrapper element that we create and wrap around the images has a height equal to a single image and a width equal to the sum of all image widths. The #viewer element on the other hand has both a width and a height equal to a single image so that only one image is visible at any one time. With JavaScript disabled, the images will appear to stack up on top of each other, but once the #slide wrapper element has been created the images are set to float in order to stack up horizontally.
Custom Animations We'll use easing in this example, so be sure to link to the easing plugin directly after the jQuery reference at the end of the : Time for action – initializing variables and prepping the widget First we need to prepare the underlying markup and store some element selectors: $("#viewer").wrapInner(""); var container = $("#slider"), prev = container.find("#prev"), prevChild = prev.find("a"), next = container.find("#next").removeClass("hidden"), nextChild = next.find("a"), slide = container.find("#slide"), key = "image1", details = { image1: { position: 0, title: slide.children().eq(0).attr("alt") }, image2: { position: -400, title: slide.children().eq(1).attr("alt") }, image3: { position: -800, title: slide.children().eq(2).attr("alt") }, image4: { position: -1200, title: slide.children().eq(3).attr("alt") }, image5: { position: -1600, title: slide.children().eq(4).attr("alt") } }; $("", { id: "title", text: details[key].title }).prependTo("#slider"); [ 106 ]
- Page 76 and 77: 3 Managing Animations Like most of
- Page 78 and 79: [ 57 ] Chapter 3 A custom queue tha
- Page 80 and 81: If we wish to see how many function
- Page 82 and 83: 2. What does the queue() method ret
- Page 84 and 85: [ 63 ] Chapter 3 The argument we su
- Page 86 and 87: [ 65 ] Chapter 3 We pass a callback
- Page 88 and 89: [ 67 ] Chapter 3 The first argument
- Page 90 and 91: Delaying queue execution [ 69 ] Cha
- Page 92 and 93: [ 71 ] Chapter 3 Also note that the
- Page 94 and 95: 4 Sliding Animations Another type o
- Page 96 and 97: Time for action - creating a slide-
- Page 98 and 99: [ 77 ] Chapter 4 header form input
- Page 100 and 101: Pop quiz - sliding elements down 1.
- Page 102 and 103: Download from Wow! eBook }); }); $
- Page 104 and 105: Toggling the slide [ 83 ] Chapter 4
- Page 106 and 107: [ 85 ] Chapter 4 } h2 { margin:0; p
- Page 108 and 109: [ 87 ] Chapter 4 The previous scree
- Page 110 and 111: Pop quiz - using slideToggle 1. Wha
- Page 112 and 113: [ 91 ] Chapter 4 Easing is a great
- Page 114 and 115: [ 93 ] Chapter 4 Home Articles J
- Page 116 and 117: [ 95 ] Chapter 4 3. Save this file
- Page 118 and 119: In the previous screenshot, we see
- Page 120 and 121: Pop quiz - fixing the flicker 1. Wh
- Page 122 and 123: 5 Custom Animations The predefined
- Page 124 and 125: An alternative syntax for animate()
- Page 128 and 129: [ 107 ] Chapter 5 What just happene
- Page 130 and 131: [ 109 ] Chapter 5 Although not esse
- Page 132 and 133: [ 111 ] Chapter 5 The previous scre
- Page 134 and 135: [ 113 ] Chapter 5 The styles we use
- Page 136 and 137: [ 115 ] Chapter 5 What just happene
- Page 138 and 139: }, html: copy, width: expander.widt
- Page 140 and 141: [ 119 ] Chapter 5 If the image alre
- Page 142 and 143: [ 121 ] Chapter 5 d. Two objects wh
- Page 144 and 145: [ 123 ] Chapter 5 text-align:center
- Page 146 and 147: [ 125 ] Chapter 5 What just happene
- Page 148 and 149: [ 127 ] Chapter 5 Finally, we retur
- Page 150 and 151: [ 129 ] Chapter 5 Once we've define
- Page 152 and 153: } }; $(config.selector).find("a").c
- Page 154 and 155: [ 133 ] Chapter 5 In the previous s
- Page 156: Have a go hero - extending the plug
- Page 159 and 160: Extended Animations with jQuery UI
- Page 161 and 162: Extended Animations with jQuery UI
- Page 163 and 164: Extended Animations with jQuery UI
- Page 165 and 166: Extended Animations with jQuery UI
- Page 167 and 168: Extended Animations with jQuery UI
- Page 169 and 170: Extended Animations with jQuery UI
- Page 171 and 172: Download from Wow! eBook Extended
- Page 173 and 174: Extended Animations with jQuery UI
- Page 175 and 176: Extended Animations with jQuery UI
[ 105 ]<br />
Chapter 5<br />
width:295px; margin:0 auto; padding:0; list-style-type:none;<br />
}<br />
#slider ul:after {<br />
content:"."; visibility:hidden; display:block; height:0;<br />
clear:both;<br />
}<br />
#slider li { margin-right:10px; float:left; }<br />
#prev, #next { position:absolute; top:175px; }<br />
#prev { left:20px; }<br />
#next { position:absolute; right:10px; }<br />
.hidden { display:none; }<br />
#slide {<br />
width:2000px; height:300px; position:absolute; top:0; left:0;<br />
}<br />
#slide img { float:left; }<br />
#title { margin:0; text-align:center; }<br />
5. Save this in the css folder as animate-position.css, and don't forget to link<br />
to the new stylesheet from the <strong>of</strong> our page. Run the page in your browser<br />
now, before we get into the scripting, so that you can see how the widget behaves<br />
without the accompanying script. You should find that any image can be viewed by<br />
clicking its corresponding link using only CSS, and this will work in any browser. The<br />
previous and next arrows are hidden with our CSS because these will simply not<br />
work with JS turned <strong>of</strong>f and the image titles are not displayed, but the widget's core<br />
functionality is still fully accessible.<br />
What just happened?<br />
The underlying HTML in this example is very straightforward. We have an outer container for<br />
the content-viewer as a whole, then within this we have a container for our content panels<br />
(simple images in this example) and a navigation structure to allow the different panels to<br />
be viewed.<br />
Some <strong>of</strong> the elements we've added style rules for in our CSS file aren't hardcoded into the<br />
underlying markup, but will be created as necessary when needed. Doing it this way ensures<br />
that the content-viewer is still usable even when the visitor has JavaScript disabled.<br />
One important point to note is that the #slide wrapper element that we create and wrap<br />
around the images has a height equal to a single image and a width equal to the sum <strong>of</strong><br />
all image widths. The #viewer element on the other hand has both a width and a height<br />
equal to a single image so that only one image is visible at any one time.<br />
With JavaScript disabled, the images will appear to stack up on top <strong>of</strong> each other, but once<br />
the #slide wrapper element has been created the images are set to float in order to stack<br />
up horizontally.