我創建的東西simular使用jQuery用戶界面的對話框燈箱
看到這個線程:https://stackoverflow.com/a/24190496/3679978
的jsfiddle: http://jsfiddle.net/8Lnt4/52/
//Creates the div element in jQuery
var container = $('<div/>');
// Creates a variable holding html string to go in above container
// Note I made the same image thats going to be enlarged into a smaller 120x90 thumbnail
var tempimg = '<div id="dialog" style="display: none;"><img id="image" src=""/></div><div class="myImage"><img src="http://www.w3schools.com/images/pulpit.jpg" alt="myimage" width="120" height="90"/></div> Click to enlarge';
// Upon clicking the .myImage Class in the container (which is the thumbnail) Open a jQueryUI Dialog...
container.on('click', '.myImage', function() { $('#dialog').dialog(
//...which upon when it's opened...
{open: function(){
///... assign a variable that can acess the div id 'image'...
imageTag = $('#image');
///... and set the image src in #image (note that it'll be the fullsize this time)...
imageTag.attr("src","http://www.w3schools.com/images/pulpit.jpg");
},closeOnEscape: true, modal:true});
});
container.html(tempimg);