专业网站建设公司怎么做,常德尚一网,wordpress音频防盗链,沈阳祥云医院男科怎么样如果您要使用纯JavaScript#xff0c;则可以设置onclick事件侦听器并获取图像的实际大小(确定图像在浏览器中的原始大小吗#xff1f;)#xff0c;然后将此大小设置为image。(如果您希望第二次单击将其设置为旧尺寸#xff0c;请将旧尺寸保存到全局变量中#xff0c;然后进…如果您要使用纯JavaScript则可以设置onclick事件侦听器并获取图像的实际大小(确定图像在浏览器中的原始大小吗)然后将此大小设置为image。(如果您希望第二次单击将其设置为旧尺寸请将旧尺寸保存到全局变量中然后进行设置)。看起来像这样我对纯JavaScript不太满意但我想是这样。将此代码添加到文件中的某个位置。它将为每个图像运行window.onload function() {images document.getElementsByTagName(img);for (var i 0; i images.length; i){images[i].onclick function(e){var isBig e.target.getAttribute(isBig);if (isBig undefined || isBig false){// make it bige.target.setAttribute(isBig, true);e.target.setAttribute(oldWidth, e.target.offsetWidth);e.target.setAttribute(oldHeight, e.target.offsetWidth);var newImg new Image();newImg.onload function() {e.target.style.width newImg.widthpx;e.target.style.height newImg.heightpx;}newImg.src e.target.getAttribute(src);}else {// make it smalle.target.setAttribute(isBig, false);e.target.style.width e.target.getAttribute(oldWidth)px;e.target.style.height e.target.getAttribute(oldHeight)px;}}}}这会将图像的宽度和高度设置为原始大小。如果要使用绝对定位使其全屏显示则需要创建一个新元素和img标签。您只需要将其src设置为图像的src。然后您可以显示该图像。例子Xfunction closeImage() {document.getElementById(bigImage).style.visibility hidden;}images document.getElementsByTagName(img);for (var i 0; i images.length; i){// on image clickimages[i].onclick function(e){// set image srcdocument.getElementById(bigImageChild).src e.target.src;// show imagedocument.getElementById(bigImage).style.visibility visible;}}