jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 123 ] Chapter 5 text-align:center; text-decoration:none; font:90px "Palatino Linotype", "Book Antiqua", Palatino, serif; line-height:400%; } #frame a:hover { color:#fff; text-shadow:0 0 5px #000; filter:alpha( opacity = 100); filter: Shadow(Color=#000, Direction=0); } #frame a:focus { outline:none; } #prev { left:0; } #next { right:0; } #overlay { width:100%; height:100%; position:absolute; left:0; top:0; z-index:3; } #overlay div { position:absolute; } 5. Save this in the css folder as advanced-transitions.css. What just happened? All we have on the underlying page are the images we wish to transition between within a container. It's best to keep the markup requirements for plugins as simple as possible so that they are easy for others to use and don't place undue restrictions on the elements or structure they want to use. The images are positioned absolutely within the container using CSS so that they stack up on top of one another, and we set our visible class on the first element to ensure one image is above the rest in the stack. Most of the styling goes towards the previous and next anchors, which we'll create with the plugin. These are set so that each one will take up exactly half of the container and are positioned to appear side-by-side. We set the z-index of these links so that they appear above all of the images. The font-size is ramped up considerably, and an excessive line-height means we don't need to middle-align the text with padding. In most browsers, we simply set the color of the anchors to transparent, which hides them. Then we set the color to white in the hover state. This won't work too well in IE however, so instead we set the link initially to transparent with the Microsoft opacity filter and then set it to fully opaque in the hover, which serves the same purpose.
Custom Animations Another IE-specific fix IE also presents us with another problem in that the clickable area of our links will only extend the height of the text within them because of their absolute positioning. We can overcome this by setting a reference to a background-image. The best part is that the image doesn't even need to exist for the fix to work (so you'll find no corresponding transparent.gif file in the book's companion code bundle). The fix has no detrimental effects on normal browsers. Creating the plugin Now let's create the plugin itself. Unlike most of the other example code we've looked at, the code for our plugin will go into its own separate file. Time for action – adding a license and defining configurable options In a new file create the following outer structure for the plugin: /* Plugin name jQuery plugin version 1.0 */ Copyright (c) date copyright holder License(s) ;(function($) { $.tranzify = { defaults: { transitionWidth: 40, transitionHeight: "100%", containerID: "overlay", transitionType: "venetian", prevID: "prev", nextID: "next", visibleClass: "visible" } }; })(jQuery); [ 124 ]
- 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 126 and 127: [ 105 ] Chapter 5 width:295px; marg
- 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 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
- Page 177 and 178: Extended Animations with jQuery UI
- Page 179 and 180: Extended Animations with jQuery UI
- Page 181 and 182: Extended Animations with jQuery UI
- Page 183 and 184: Extended Animations with jQuery UI
- Page 185 and 186: Extended Animations with jQuery UI
- Page 187 and 188: Extended Animations with jQuery UI
- Page 189 and 190: Extended Animations with jQuery UI
- Page 191 and 192: Extended Animations with jQuery UI
- Page 193 and 194: Extended Animations with jQuery UI
[ 123 ]<br />
Chapter 5<br />
text-align:center; text-decoration:none;<br />
font:90px "Palatino Linotype", "Book Antiqua", Palatino, serif;<br />
line-height:400%;<br />
}<br />
#frame a:hover {<br />
color:#fff; text-shadow:0 0 5px #000; filter:alpha(<br />
opacity = 100);<br />
filter: Shadow(Color=#000, Direction=0);<br />
}<br />
#frame a:focus { outline:none; }<br />
#prev { left:0; }<br />
#next { right:0; }<br />
#overlay {<br />
width:100%; height:100%; position:absolute; left:0; top:0;<br />
z-index:3;<br />
}<br />
#overlay div { position:absolute; }<br />
5. Save this in the css folder as advanced-transitions.css.<br />
What just happened?<br />
All we have on the underlying page are the images we wish to transition between within<br />
a container. It's best to keep the markup requirements for plugins as simple as possible so<br />
that they are easy for others to use and don't place undue restrictions on the elements or<br />
structure they want to use.<br />
The images are positioned absolutely within the container using CSS so that they stack up on<br />
top <strong>of</strong> one another, and we set our visible class on the first element to ensure one image<br />
is above the rest in the stack.<br />
Most <strong>of</strong> the styling goes towards the previous and next anchors, which we'll create with<br />
the plugin. These are set so that each one will take up exactly half <strong>of</strong> the container and are<br />
positioned to appear side-by-side. We set the z-index <strong>of</strong> these links so that they appear<br />
above all <strong>of</strong> the images. The font-size is ramped up considerably, and an excessive<br />
line-height means we don't need to middle-align the text with padding.<br />
In most browsers, we simply set the color <strong>of</strong> the anchors to transparent, which hides<br />
them. Then we set the color to white in the hover state. This won't work too well in IE<br />
however, so instead we set the link initially to transparent with the Micros<strong>of</strong>t opacity<br />
filter and then set it to fully opaque in the hover, which serves the same purpose.