Link to home
Start Free TrialLog in
Avatar of canuckconsulting
canuckconsultingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Need to animate buttons on webpage

I have a web page with buttons as shown here:
User generated image
They work fine but there is no visual indication when the get clicked.  What is the best and quickest way for me to visually respond to a click?  Here is one of the buttons files as an example:

User generated image
For image tools I have Gimp though I am a novice with it.  I also have the Jquery and jqueryUI libraries working on this page if that's of any use.
Avatar of Elxn
Elxn
Flag of United States of America image

You can use jquery to do something like this easily.

Just give your images a class and a tabindex:
<img class="photo" tabindex="0" src="pic.jpg" />

Open in new window


Then use css to define a new image for your image when it has the focus (i.e. is clicked on).
.photo:focus{
   background:url(click-pic.jpg);
}

Open in new window


Then use jquery to remove the focus after a short period of time:
$( ".photo" ).click(function() {
    $(this).blur().delay(500);
});

Open in new window


That should probably be a really easy way to do this.
you'll probably want to use a unique ID instead of a class as you'll need various css for the different pictures.  Forgot to do that.  Just define css for each unique ID and you can change the code accordingly.

Or to make your life easier you can change the color of the class's css and just modify the way the image looks when they click on it.  Like so:

.photo:focus{
	filter: saturate(500%);
	-webkit-filter: saturate(500%);
	-moz-filter: saturate(500%);
	-o-filter: saturate(500%);
	-ms-filter: saturate(500%);
}

Open in new window


You won't have to mess around with all those ID's in your CSS if you do it this way...
ASKER CERTIFIED SOLUTION
Avatar of Elxn
Elxn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of canuckconsulting

ASKER

Thanks Nick!

Interestingly that doesn't work for IE but looks good in Chrome.
Hmm.  I'm pretty new to jQuery, but I am pretty sure jQuery works very hard to be cross-browser compatible so the problem is probably elsewhere.  My guess is that IE doesn't allow you to set a tab index for elements like a img tag.
Solution, just fake IE out by using links...  Check out the solution for IE here
and remember you should be able modify the saturation (or other aspects) with the CSS i already gave you in an earlier comment so you don't have to specify unique images for each button and button focus.
Oh just found out CSS filter support is not in IE... So forget that idea...