jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of

02.06.2013 Views

[ 249 ] Chapter 9 Left Right 2. Save the page as skew.html. Next in a new file add the following code: #viewer { width:700px; height:220px; padding:100px 0 30px; margin:auto; border:1px solid #000; position:relative; } #flow:after { content:""; display:block; height:0; clear:both; visibility:hidden; } #flow img { display:block; margin-left:-165px; position:relative; top:-15px; left:245px; float:left; background-color:#fff; } #viewer li { list-style-type:none; position:absolute; bottom:10px; } #left { left:20px; } #right { right:20px; } 3. Save this file in the css directory as skew.css. What just happened? We're using a simple collection of elements for this example. We use an outer container, mostly for positioning purposes so that we can center the widget in the viewport and position other elements within it. The elements are what we will be applying the skew animations to, so these are isolated in their own container to make selecting them in the script later on easier. We also have a list element containing two links. These will be used to trigger the animations. The CSS is as light as the HTML. We simply position the container, the images, and the controls as required for the example. All of the fun CSS3 we'll set and manipulate using the script. You should note that this example isn't progressively-enhanced as this would deviate too far from an already quite large example, as we'll see in a moment when we add the JavaScript.

CSS3 Animations Time for action – initializing the widget The first thing we need to do is set up the images ready to have their skew manipulated. We can also add the function that will return the correct vendor-specific prefix for the transform style property that we used in the last example. In the empty function at the bottom of the HTML page, add the following code: var viewer = $("#viewer"), flow = viewer.find("#flow"), order = flow.children().length, oneRad = 1 * (Math.PI / 180), matrix = ["matrix(", 1, ",", 0, ",", 0, ",", 1, ",", "0px,", "0px)"], msMatrix = "progid:DXImageTransform.Microsoft.Matrix( sizingMethod='auto expand')", getVendor = function() { var prefix = null, vendorStrings = { pure: "transform", moz: "-moz-transform", webkit: "-webkit-transform", op: "-o-transform" }; for (props in vendorStrings) { if(flow.css(vendorStrings[props]) === "none") { prefix = vendorStrings[props]; } } if (prefix === null) { prefix = "filter"; } return prefix; }, vendor = getVendor(), property = (vendor !== "filter") ? matrix.join("") : msMatrix; flow.children().eq(0).addClass("flat").css(vendor, property).css("zIndex", order + 1); flow.children().not(":first").each(function(i) { el = flow.children().eq(i + 1); [ 250 ]

CSS3 <strong>Animation</strong>s<br />

Time for action – initializing the widget<br />

The first thing we need to do is set up the images ready to have their skew manipulated. We<br />

can also add the function that will return the correct vendor-specific prefix for the transform<br />

style property that we used in the last example. In the empty function at the bottom <strong>of</strong> the<br />

HTML page, add the following code:<br />

var viewer = $("#viewer"),<br />

flow = viewer.find("#flow"),<br />

order = flow.children().length,<br />

oneRad = 1 * (Math.PI / 180),<br />

matrix = ["matrix(", 1, ",", 0, ",", 0, ",", 1, ",",<br />

"0px,", "0px)"],<br />

msMatrix = "progid:DXImageTransform.Micros<strong>of</strong>t.Matrix(<br />

sizingMethod='auto expand')",<br />

getVendor = function() {<br />

var prefix = null,<br />

vendorStrings = {<br />

pure: "transform",<br />

moz: "-moz-transform",<br />

webkit: "-webkit-transform",<br />

op: "-o-transform"<br />

};<br />

for (props in vendorStrings) {<br />

if(flow.css(vendorStrings[props]) === "none") {<br />

prefix = vendorStrings[props];<br />

}<br />

}<br />

if (prefix === null) {<br />

prefix = "filter";<br />

}<br />

return prefix;<br />

},<br />

vendor = getVendor(),<br />

property = (vendor !== "filter") ? matrix.join("") : msMatrix;<br />

flow.children().eq(0).addClass("flat").css(vendor,<br />

property).css("z<strong>Index</strong>", order + 1);<br />

flow.children().not(":first").each(function(i) {<br />

el = flow.children().eq(i + 1);<br />

[ 250 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!