我一直在试图移动小图像(缩略图),但它不会移动。它只是固定在左边。我试过给它一个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);
}
HTML正文
<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>
提供的jsfiddle例子吗? – hjpotter92 2013-05-14 13:22:46
你是如何尝试移动它的? – Aioros 2013-05-14 13:28:21
@Aioros把图像放入div然后给它一个id然后我尝试在css样式中设置边距 – Elvain 2013-05-14 13:31:11