我可以建议,在我看来,最好的解决方案?这是使用jQuery 1.4+。
这里有一个包含所有照片的容器。注意添加的类。
<div id="photo-container">
<a href="image1.jpg">
<img class="popup-image" src="thumbnail1.jpg" pbsrc="image1.jpg" />
</a>
<a href="image2.jpg">
<img class="popup-image" src="thumbnail2.jpg" pbsrc="image2.jpg" />
</a>
<a href="image3.jpg">
<img class="popup-image" src="thumbnail3.jpg" pbsrc="image3.jpg"/>
</a>
</div>
的,那么你做一个单一的事件处理程序是这样的:
<script type="text/javascript">
$(document).ready(function(){
var container = $('#photo-container');
// let's bind our event handler
container.bind('click', function(event){
// thus we find (if any) the image the user has clicked on
var target = $(event.target).closest('img.popup-image');
// If the user has not hit any image, we do not handle the click
if (!target.length) return;
event.preventDefault(); // instead of return false;
// And here you can do what you want to your image
// which you can get from target
Pop(target.get(0));
});
});
</script>
这似乎是最好的解决办法(waaay比我找到了更好的)。 但是,我的情况并不是很好,因为这个PopBox thingy试图重写onclick事件处理程序,所以当你再次点击它时它会再次关闭。将需要看看这个... – arturh 2008-09-15 15:06:16