I create small animated graphics using CSS and jQuery. There are a series of animations which switch from slide to slide when you click on a button.
I currently use this method:
<script>
$(function() {
$("#z-tab1").click(function() {
$(".zSlide1").removeClass("zhide");
$(".zSlide2").removeClass("zshow");
$(".zSlide3").removeClass("zshow");
//hide previous slides
$(".zSlide1").addClass("zshow");
$(".zSlide2").addClass("zhide");
$(".zSlide3").addClass("zhide");
</script>
<style>
.zhide{ display:none; }
.zshow{ display:block;}
/*slide 1 */
.zSlide1 {
width:100%;
height:100%;
max-width:600px;
min-height:500px;
min-width:320px;}
Is there a better way to achieve this?
Thanks in advance ;)
You can do something like this:
// set an active slide to display when page loads $('.elem1').addClass('activeSlide');
Example here: http://jsfiddle.net/WrQ4L/1/
Keep in mind that this method requires to have class names numbered ascending(the initial value of "i" is equal to the first class number -> elem1)