0
我一直試圖添加一個關閉按鈕(右上角)此燈箱有一段時間沒有成功。任何人都可以發送一個工作的JSFiddle或Codepen與添加的關閉功能?添加關閉按鈕燈箱
謝謝
http://codepen.io/stoypenny/pen/pJkcK
這是JS
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
$overlay.append($image);
$("#body").append($overlay);
$("#imageGallery a").click(function(event){
event.preventDefault();
//Get image link
var imageLocation = $(this).children().attr("src");
//Add image source to the image
$image.attr("src", imageLocation);
//Set styles so that the image doesn't display at resolutions beyond the screen size
$image.css({maxWidth: "70%", maxHeight: "70%", marginTop: "10%" });
//Display the overlay
$overlay.show();
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});
非常感謝。任何方式讓它出現在圖像本身的右上角?再次感謝 – samish
測試一些配偶 - 是的,這將是它的理想場所,但迄今爲止我沒有嘗試過的雪茄 - 這就是爲什麼我把這個「快速」解決方案給你......如果我可以想出更好的東西,我會更新我的答案。 – Michael
你知道如何添加懸停效果嗎?因此,如果我將鼠標懸停在x按鈕上,它會發生一些變化? – samish