I’m a beginner and have this simple script. My question is how to set the time interval between fading out the mainImg and fading in the Img(1,2,3) because the source of the mainImgchanges directly when fading out:
<head>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function(){
$("#img1").click(function(){
$("#mainImg").fadeOut("slow");
$("#mainImg").attr("src","images/1.png");
$("#mainImg").fadeIn("slow");
});
$("#img2").click(function(){
$("#mainImg").fadeOut("slow");
$("#mainImg").attr("src","images/2.png");
$("#mainImg").fadeIn("slow");
});
$("#img3").click(function(){
$("#mainImg").fadeOut("slow");
$("#mainImg").attr("src","images/3.PNG");
$("#mainImg").fadeIn("slow");
});
});
</script>
<style type="text/css">
#theImage{
width:256px;
height:256px;
}
.thumb{
width:100px;
height:100px;
cursor:pointer;
margin-right:20px;
margin-left:20px;
}
</style>
</head>
<body>
<div id="theImage"><img id="mainImg" src="images/1.png" width="256" height="256" /></div>
<img id="img1" src="images/1.png" class="thumb" /> <img id="img2" src="images/2.png" class="thumb" /> <img id="img3" src="images/3.PNG" class="thumb" />
</body>
You can use one function for all clicks like this;
Here is jsFiddle example. Don’t mind CSS, I had to change them for display purposes.