This transition is achieved by using the CSS3 transition property - property which is supported in all major browsers like Chrome, Firefox, Opera, Safari (for Safari we will need the -webkit- prefix to get this effect).
The CSS3 Transition Syntax
The syntax of the transition supports four values:- the property affected by the transition, such as color, border, background, width, etc.
- the duration of this transition in seconds, i.e., how long it will take to change your style completely
- the delay time for the transition to be executed, also in seconds, i.e., how long it takes for the transition to start when the mouse hovers over that element;
Check out the code below:
.example {In the example above, the elements with the class .example will become wide within two seconds as the mouse passes over them.
transition-property: width; /* property that undergoes a transition */
transition-duration: 2s; /* duration of the transition */
transition-timing-function: linear; /* timing-function */
transition-delay: 0; /* length of time to delay the start of a transition */
/* now we will repeat the entire declaration with the -webkit- prefix for the effect to work in Chrome and Safari */
-webkit-transition-property: width;
-webkit-transition-duration: 2s;
-webkit-transition-timing-function: linear;
-webkit-transition-delay: 0;
}
When we define the style of a link, usually we need to use the a:link selector, and when defining the style when the mouse is over the link, we need to use the :hover selector. However, the transition can be used in any HTML element, not just links. To make the transition effect to work properly, we should define two blocks of style for that element, i.e. the normal style for a tag/id/class and the style on mouse :hover for a specific tag/id/class.
For example:
tag, #id, .class {You can add the same style on multiple selectors separated by commas as I have done above, although that's not necessary.
/* insert here the styles that you want for the selector */
/* insert below the transition effects */
}
tag:hover, #id:hover, class:hover {
/* Insert here the styles for when the mouse is over the element */
/* here it is not necessary to repeat the declaration of the transition */
}
Below are some transition examples with their respective codes.
I will not use the transition-timing-function in these examples because it makes no difference, as the first value is the duration in seconds and the second is the delay.
Example 1
/* with a single property */
#example1 {
background-color: #FFFF00;
-moz-transition-property: background-color;
-moz-transition-duration: 2s;
-webkit-transition-property: background-color;
-webkit-transition-duration: 2s;
-o-transition-property: background-color;
-o-transition-duration: 2s;
}
#example1:hover {
background-color: #B5E2FF;
}
Example 2
/* with four properties and delay */Example 3
#example2 {
background-color: #9c3;
border: 8px solid #690;
padding: 20px;
color: #fff;
-moz-transition-property: background-color,border;
-moz-transition-duration: 1s;
-webkit-transition-property: background-color,border;
-webkit-transition-duration: 1s;
-o-transition-property: background-color,border;
-o-transition-duration: 1s;
}
#example2:hover {
background-color: #690;
border: 8px dashed #fff;
color: #FFFF00;
-moz-transition-property: background-color,border;
-moz-transition-duration: 2s;
-webkit-transition-property: background-color,border;
-webkit-transition-duration: 2s;
-o-transition-property: background-color,border;
-o-transition-duration: 2s;
}
/* with seven properties and delay */Example 4
#example3 {
padding: 15px;
background-color: #FF7CA6;
font-size: 16px;
width: 30%;
font-weight: bold;
color: #fff;
height: 20px;
-moz-transition-property: background-color,width,height,padding,font-size,color;
-moz-transition-duration: 1s;
-webkit-transition-property: background-color,width,height,padding,font-size,color;
-webkit-transition-duration: 1s;
-o-transition-property: background-color,width,height,padding,font-size,color;
-o-transition-duration: 1s;
}
#example3:hover {
background-color:#9c3;
width: 60%;
height: 60px;
padding: 50px;
font-size: 30px;
color: #FFFF00;
-moz-transition-property: background-color,width,height,padding,font-size,color;
-moz-transition-duration: 2s;
-webkit-transition-property: background-color,width,height,padding,font-size,color;
-webkit-transition-duration: 2s;
-o-transition-property: background-color,width,height,padding,font-size,color;
-o-transition-duration: 2s;
}
/* with all the properties simultaneously */Final words:
#example4 {
padding: 15px;
background-color: #9c3;
color: #fff;
font-size: 16px;
width: 30%;
font-weight: bold;
transition: all 2s;
-webkit-transition: all 2s;
}
#example4:hover {
background-color: #FF7CA6;
color: #242424;
width: 60%;
}
- the transition declarations need to appear in the CSS. In Blogger, the CSS is located before ]]</b:skin>
- as you can see in the examples above, you can assign different rules for the transitions of different elements in a single rule - just separate them with commas.
- it is not mandatory to use the four properties in the transition declaration, but their order must always look like this: property/duration/timing-function/delay.
- the duration and delay values must be expressed in seconds, but sometimes a second is a long time for a transition. In this case you can use values with milliseconds, for example, .5s means half a second.
- In small time intervals, the timing of the transition-function property does not give a remarkable effect being most useful only in more advanced animations. The possible values are either ease (the default, which makes the transition with a slow beginning, then gets faster and ends slowly), linear (the same transition speed from beginning to end), ease-in (transition begins slowly and then the speed increases), ease-out (transition starts fast and slows down at the end) and ease-in-out.
Tourism or Travel Loans SEO Laws and lawyers Hosting Mesothelioma Law Firm Loans And Donation Insurance Donate Car for Tax Credit Attomey Conference Call AUTO ACCIDENT LAWYER DENVER Gas/Electricity Donate Car to Charity California mesothelioma attorneys california Mortgage Classes NUNAVUT CULTURE Donate cars in ma Credit Software Fatcow Recovery domain registration yahoo structured settlement buyer mesothelioma survival rates Rehab Donate car to charity California Transfer DAYTON FREIGHT LINES ANNUITY SETTLEMENT Donate Lawyer mesothelioma claim Car insurance quotes Colorado Blogs Based On Donations Claim STRUCTURE SETTLEMENTS Nunavut culture Treatment Cord Blood Trading Degree Attormey LOS ANGELES AUTO ACCIDENT ATTORNEY Online casino · Mortgage Adviser All topics related to traffic from USA How to donate a car in California STRUCTURED ANNUITY SETTLEMENT Health Business Technology SELLING A STRUCTURED SETTLEMENT ANNUITY Digital Photography Business Fastest VPS hosting domain name yahoo structured settlement annuity companies Dreamhost structured settlements annuities · World Trade Center Footage
0 comentarios:
Publicar un comentario