我可以建議,在我看來,最好的解決方案?這是使用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