我一直在尝试移动小图像(缩略图),但它不会移动。它只是固定在左边。我试过给它一个 div id 并为其设置边距,但它不起作用。
以下是代码:
JavaScript
function showImage(imgName) {
document.getElementById('largeImg').src = imgName;
showLargeImagePanel();
unselectAll();
}
function showLargeImagePanel() {
document.getElementById('largeImgPanel').style.visibility = 'visible';
}
function unselectAll() {
if(document.selection) document.selection.empty();
if(window.getSelection) window.getSelection().removeAllRanges();
}
function hideMe(obj) {
obj.style.visibility = 'hidden';
}
CSS
#largeImgPanel {
text-align: center;
visibility: hidden;
position: fixed;
z-index: 100;
top: 0; left: 0; width: 100%; height: 100%;
background-color: rgba(100,100,100, 0.5);
}
正文
<body>
<img src="images/small1.png" style="cursor:pointer" onclick="showImage('images/large1.jpg');" />
<img src="images/small2.jpg" style="cursor:pointer" onclick="showImage('images/large2.jpg');" />
<img src="3_small.jpeg" style="cursor:pointer" onclick="showImage('3_large.jpeg');" />
<div id="largeImgPanel" onclick="hideMe(this);">
<img id="largeImg" margin: 0; padding: 0;" />
</div>
</body>
</html>