as4s1n
New Member
- Messages
- 174
- Reaction score
- 4
- Points
- 0
I am working on a thumbnail viewer and it's mostly complete. However, when the user opens it and then clicks on the same thumbnail, or any other for that matter, it reopens the div. I am using the $.animate() function to set the height and width from 0 to the image height.
HTML:
jQuery:
CSS:
My guess would be something with the
but jQuery doesn't allow that.
Please help. Thanks.
Here is a link
HTML:
HTML:
<div id="thumbs">
<img src="i1.jpg" />
<img src="i2.jpg" />
</div>
<div id="display"><img src="" /><div style="clear:both;color:#fff;text-align:right;">Close X</div></div>
jQuery:
Code:
// Thumbnail viewer
$(document).ready(function() {
$("#thumbs img").click(showBox);
$("#display").click(hideBox);
})
function showBox() {
var src = $(this).attr("src");
var imgH = $("#display img").height()+10;
var imgW = $("#display img").width();
$("#display").css("display","block");
$("#display img").attr("src",src);
$("#display").animate({height:imgH},"normal");
$("#display").animate({width:imgW},"normal");
}
function hideBox() {
$("#display").css("display","none");
$("#display").css("height","0");
$("#display").css("width","0");
}
CSS:
Code:
#thumbs img {
height:90px;
width:90px;
}
#display {
background:#000;
cursor:pointer;
display:none;
height:0;
left:250px;
padding:10px;
position:absolute;
top:50px;
width:0;
}
#display img {
max-height:800px;
max-width:600px;
}
My guess would be something with the
Code:
if($(this).attr("height").is()) {}
but jQuery doesn't allow that.
Please help. Thanks.
Here is a link
Last edited: