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:HTML Code:<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>
CSS: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"); }
My guess would be something with theCode:#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; }
but jQuery doesn't allow that.Code:if($(this).attr("height").is()) {}
Please help. Thanks.
Here is a link


LinkBack URL
About LinkBacks

Reply With Quote

