Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, this is possible to add hover animation on any element using purely HTML markup and CSS.</p> <pre><code>.animated { transition: prop; prop: value1; } .animated:hover { prop: value2; } </code></pre> <p>Where <code>prop</code> is the CSS property that you wan't to be animated. This works very well in most browsers. Also, it is possible to create this behavior with scripts as well.</p> <p>With your markup, the best and easiest script-free solution to animate is to use <code>:hover</code> and <code>transition</code>. Here is a fiddle how to animate <code>margin-left</code>: <a href="http://jsfiddle.net/9kpfW/" rel="nofollow">http://jsfiddle.net/9kpfW/</a></p> <p><em>You can animate any property with a numeric measure</em>. (12px, 12em, 12% etc.) It is possible to add hover affects with non-numeric properties (i.e. <code>text-align</code>) as well, but you can't apply a transition. Also, it is possible to animate multiple properties on the same element using <code>transition</code>.</p> <p>So, you can create very rich effects purely with CSS. No JavaScript is necessary. <code>:hover</code> effects work well in almost every browser, including ancient versions of Internet Explorer. However, if you need to support outdated browsers with the same animated transition effect, you need to use JavaScript, which is supported and enabled in almost every browser. I recommend using jQuery JavaScript library to simplify your scripts.</p> <p>Based on luckyamit's answer, here is a trivial example of the same <code>margin-left</code> animation using jQuery. This works well in almost any web browser, including ancient versions.</p> <pre><code>$(".nav li").hover( function() { $(this).find("a").stop().animate({"margin-left" : "40px"}); }, function() { $(this).find("a").stop().animate({"margin-left": "5px"}); } ); </code></pre> <p>Fiddle: <a href="http://jsfiddle.net/LxAva/1/" rel="nofollow">http://jsfiddle.net/LxAva/1/</a></p> <p>However, if you don't need to serve the same experience in those rare browsers, I recommend the pure-CSS solution, because of the principle of decoupling markup, style and logic. Rich transition effects are way more related to style than logic, so they should be solved with CSS instead of JavaScript. Also, in most cases CSS is easier and faster to implement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload