1%%Here is our dear friend, the DOM Element.
- Fade in a square, perhaps 200px.
Web design is a perpetual process of finding better ways of arranging DOM elements in the browser.
For so long, our only options were to float 1%%left or 2%%right
- DE floats left
- DE floats right
Or using a coordinate system with position.
- DE moves up and down
- DE moves left and right
However, all of the latest browsers have a new technology unlocking another dimension of possibility: CSS 3D Transforms.
Transforms let you move and rotate DOM elements along three axes of motion: 1%%4%%x, 2%%5%%y, and 3%%6%%z
- DE moves along x axis (blue)
- DE moves along y axis (green)
- DE moves along z axis (red, use perspective)
- DE rotates along x axis (blue, use perspective)
- DE rotates along y axis (green, use perspective)
- DE rotates along z axis (red, use perspective)
When combined with some settings that control perspective, you can create 3D figures out of regular DOM elements.
These perspective settings go on the container of the 3D elements.
- {code} transform-style
- {code} perspective - (animate the perspctive value on a 3D-transformed primitive)
- {code} perspective-origin - (animate the perspctive value on a 3D-transformed primitive)
These transforms go on the element you want to transform
- {code} translate
- {code} rotate
- {code} backface-visibility
Creating primitives
Since transforms are inherited by children, you can think of nested elements much like paper
Just align the two transform-origin
s of nested elements to a common edge, and it "folds" like paper:
- Show two DEs first in the same position then one folds 90° from a common edge
- Now another folds out from the second, also 90°
- The fourth folds out from the third, connecting to the first
- The fifth folds out from the third, forming one side of the cube
- The sixth folds out from the third, forming the other side and completing the cube
- The first, second, and third joints open up more, revealing the "t" shape that an unfolded paper cube makes
You can simulate other more complex objects. This slinky is not a spiral, but numerous nested
s
- Demo slinky
You can superimpose transforms on top of real images
- Demo tile
Combining with other CSS
- Demo blur filter
DOM elements can be enhanced by JavaScript. Just write in your markup and have your script add [bottom, left, right, front, back] edges.
- Make various minecraft blocks out of really simple markup+classes
- Maybe make it so clicking a surface generates the new block on that surface
Playtime! Set up a holodeck-type thing and offer six textfields to let the user transform a cube
The end
- blur filter: convert to Sass, add real 3d perspctive and shift perspective origin based on cursor position