Skip to content
Start arrow Articles arrow Simple menu animated with CSS
Simple menu animated with CSS
 

Napisany przez Administrator, z 04-05-2010 21:26

Odsłon : 106    

Opublikowane w : Programming, XHTML/CSS/JavaScript


In this article I would to show simply method to get animated, graphical buttons on your website using just Cascade Style Sheet and events.
Firstly we have to prepare buttons images using any graphic program like Gimp (I prefer using free application under GNU or BSD licence).
I will to use opacity feature, in-line JavaScript and events to make simple animation of button.

Tip: opacity feature has been different implemented in Firefox (and most browsers as well) and MS Internet Explorer because of that, we should to use both method to get animation effect in all browsers!

  • Firefox format:   opacity:1
  • IE format:            filter:alpha(opacity=100)

Opacity equal 1 for Firefox or 100 for IE means object is 0% transparent (if value of opacity is lower transparency is bigger).

Simple HTML code for link with image as button looks, for example:

<a href=”link”><img src=”image link” /></a>

Opacity feature we have to set for <img> tag

<img src=”image link” style="opacity:1;filter:alpha(opacity=100) />

For animation we should add onmouseover and onmouseout attributes, as reaction for mouse pointer movement.

<img src=”image link” style="opacity:1;filter:alpha(opacity=100)
onmouseover="this.style.opacity=0.7;this.filters.alpha.opacity=70;"
onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100"

/>

If you note I have used smaller opacity value for onmouseover attribute – it is our animation as reaction for mouse pointer moving over menu button – you can use values from 0 to 1 for Firefox and 0-100 for IE.

At the end we should to add reaction for onclick event because after click menu button will stay in mouseover state (for this example wit opacity=0.7).

<img src=”image link” style="opacity:1;filter:alpha(opacity=100)
onmouseover="this.style.opacity=0.7;this.filters.alpha.opacity=70;"
onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100"
onclick="this.style.opacity=1;this.filters.alpha.opacity=100"
/>

The same animation method we can use for text based menu but we have to set style for <a> tag, for example:

<a href="http://www.google.com" style="opacity:1;filter:alpha(opacity=100)" 
onmouseover="this.style.opacity=0.7;this.filters.alpha.opacity=70;"
onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100;
onclick="this.style.opacity=1;this.filters.alpha.opacity=100;">Google</a>


Example file: menuopacity.html

Sources:

http://www.w3schools.com/Css/css_image_transparency.asp
http://www.quirksmode.org/css/opacity.html


Ostatnie uaktualnienie : 11-05-2010 05:28

   
Drukuj
Powiązane artykuły
Zapisz do del.icio.us

Słowa kluczowe : opacity, css, javascript, HTML, xhtml, menu, website, programming


Komentarze użytkowników  
 

Średnia ocena użytkownika

   (0 głos)

 


Dodaj swój komentarz
Tylko zarejestrowani użytkownicy mogą komentować artykuły. Zaloguj się lub zarejestruj.

Żaden komentarz nie wystawiony



mXcomment 1.0.7.::.Polish Version - JoomlaPL.com Team © 2007-2010 - visualclinic.fr
License Creative Commons - Some rights reserved

Google translate

EnglishFrenchGermanPolishPortugueseRussianSpanishYiddish



Kursy NBP z 08-09-2010
walutaskupsprz. 
USD3.06193.1237st
EUR3.90413.9829st
GBP4.69044.7852st
Symfonia CDN Optima