How to use the CSS3 transition property
Along with the introduction of CSS3 comes many new features that are available for use in creating great effects; one of the most useful is the transition property.
The transition property is an important new development in CSS. It can be used to create a dynamic change effect on a div or class using a simple structure:
transition: property duration timing-function delay;
CSS3′s transition is a great way to add a little animation to sites without the large overhead of a JavaScript library like jQuery.
Demo
Before we start, you can see a demo here of the transition property in action.
Property
Firstly, in order for the transition property to work, the standard property that it will be applied to needs to be defined. Arguably the two most common properties that will be defined are width and height. To write the property standalone simply use:
transition-property: define property
Size Change
Following on, once the property has been defined then the start and end values need to be assigned. In the case of values such as width or height the property needs to be set with a start value and then an end value with some other condition.
For example, here we set the transition property to width, then the start value of width and then set the end value when the element is hovered over:
#mainheader {
transition-property:width;
width:50px;
}
#mainheader:hover {
width:75px;
}
Duration
Now that we have defined the property to transform, the start and end values, we need to define the duration of the transition. This is achieved by defining a length in either seconds or milliseconds as below:
transition-duration: duration;
Building this into the example the following code is created:
#mainheader {
transition-property:width;
transition-duration:0.5s;
width:500px;
}
#mainheader:hover {
width:750px;
}
This means that the mainheader div will expand by 25px over a duration of 5 seconds.
Timing Function
The code is sufficient to create a nice effect however we can further utilise the CSS3 transition property by using timing-function Using this property it is possible to alter the speed curve of the transition duration. The transition property is set to a linear curve by default. However, you can define ease, ease-in, ease-out, ease-in-out and even cubic-bezier to alter the speed curve. Cubic-bezier allows you to define your own values using (n,n,n,n) where n can be between 0 and 1 (for example linear would be (0,0,1,1)).
Adding in this code to our example results in:
#mainheader {
transition-property:width;
transition-timing-function:ease-in-out;
transition-duration:0.5s;
width:500px;
}
#mainheader:hover {
width:750px;
}
Delay
Furthermore, much like transition-duration, using the transition-delay property defines a pause before the transition effect begins:
transition-delay: time;
Conclusion
Finally, it is important to consider two things when using the CSS3 transition property. Firstly, most browsers in circulation at present require a browser prefix to use it (the exceptions being IE10, Opera and Firefox16+):
-moz-transition: for Firefox 15
-webkit-transition: for Chrome and Safari
(Bear in mind that IE9 and lower does not support the transition property at all.)
Secondly, although I’ve used long hand in the examples above for clarity, it’s considered best practice to write in short form, as follows:
#mainheader {
-moz-transition: width ease-in-out 0.5s 0.1s; /* for Firefox 15 */
-webkit-transition: width ease-in-out 0.5s 0.1s; /* for Chrome and Safari */
transition: width ease-in-out 0.5s 0.1s;
width:500px;
}
#mainheader:hover {
width:750px;
}
Do use the CSS3′s transition property? How does it compare to jQuery-based tweens? Let us know in the comments.
Featured image/thumbnail, motion image via Shutterstock.
Manage Multiple WordPress Sites with Just One Click – 50% off! |
2012-12-06 10:21:27
Source: http://www.webdesignerdepot.com/2012/12/how-to-use-the-css3-transition-property/
Source:
Anyone can join.
Anyone can contribute.
Anyone can become informed about their world.
"United We Stand" Click Here To Create Your Personal Citizen Journalist Account Today, Be Sure To Invite Your Friends.
Before It’s News® is a community of individuals who report on what’s going on around them, from all around the world. Anyone can join. Anyone can contribute. Anyone can become informed about their world. "United We Stand" Click Here To Create Your Personal Citizen Journalist Account Today, Be Sure To Invite Your Friends.
LION'S MANE PRODUCT
Try Our Lion’s Mane WHOLE MIND Nootropic Blend 60 Capsules
Mushrooms are having a moment. One fabulous fungus in particular, lion’s mane, may help improve memory, depression and anxiety symptoms. They are also an excellent source of nutrients that show promise as a therapy for dementia, and other neurodegenerative diseases. If you’re living with anxiety or depression, you may be curious about all the therapy options out there — including the natural ones.Our Lion’s Mane WHOLE MIND Nootropic Blend has been formulated to utilize the potency of Lion’s mane but also include the benefits of four other Highly Beneficial Mushrooms. Synergistically, they work together to Build your health through improving cognitive function and immunity regardless of your age. Our Nootropic not only improves your Cognitive Function and Activates your Immune System, but it benefits growth of Essential Gut Flora, further enhancing your Vitality.
Our Formula includes: Lion’s Mane Mushrooms which Increase Brain Power through nerve growth, lessen anxiety, reduce depression, and improve concentration. Its an excellent adaptogen, promotes sleep and improves immunity. Shiitake Mushrooms which Fight cancer cells and infectious disease, boost the immune system, promotes brain function, and serves as a source of B vitamins. Maitake Mushrooms which regulate blood sugar levels of diabetics, reduce hypertension and boosts the immune system. Reishi Mushrooms which Fight inflammation, liver disease, fatigue, tumor growth and cancer. They Improve skin disorders and soothes digestive problems, stomach ulcers and leaky gut syndrome. Chaga Mushrooms which have anti-aging effects, boost immune function, improve stamina and athletic performance, even act as a natural aphrodisiac, fighting diabetes and improving liver function. Try Our Lion’s Mane WHOLE MIND Nootropic Blend 60 Capsules Today. Be 100% Satisfied or Receive a Full Money Back Guarantee. Order Yours Today by Following This Link.
