【发布时间】:2016-05-18 07:02:11
【问题描述】:
我是 JavaScript 和 jQuery 的新手,所以这是我的问题。我如何向此代码添加一个简单的按键操作。 就像我按右箭头一样,转到下一个图像。如果我按左箭头,转到上一张图片。 我已经查过它并自己尝试了一些东西,但我无法将任何东西集成到这个特定的代码中。
现在,我可以简单地使用另一个代码并使用灯箱画廊或其他东西,但我不希望这样,因为我已经在网站上找到了某个地方,而且我无法重来。
function showImage(smSrc, lgSrc) {
document.getElementById('largeImg').src = smSrc;
showLargeImagePanel();
unselectAll();
setTimeout(function() {
document.getElementById('largeImg').src = lgSrc;
}, 1)
}
function showLargeImagePanel() {
document.getElementById('largeImgPanel').style.display = 'block';
}
function unselectAll() {
if (document.selection)
document.selection.empty();
if (window.getSelection)
window.getSelection().removeAllRanges();
}
#largeImgPanel {
text-align: center;
display: none;
position: fixed;
z-index: 100;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(100, 100, 100, 0.8);
}
<img src="./images/t_p0001.jpg" style="cursor:pointer" onclick="showImage(this.src, './images/p0001.JPG');" />
<img src="./images/t_p0002.jpg" style="cursor:pointer" onclick="showImage(this.src, './images/p0002.JPG');" />
<img src="./images/t_p0003.jpg" style="cursor:pointer" onclick="showImage(this.src, './images/p0003.JPG');" />
<img src="./images/t_p0004.jpg" style="cursor:pointer" onclick="showImage(this.src, './images/p0004.JPG');" />
<div id="largeImgPanel" onclick="this.style.display='none'">
<img id="largeImg" style="height:100%; margin:0; padding:0;" />
</div>
【问题讨论】:
-
我没有看到你在代码中的任何地方使用 Jquery 吗?
-
我不使用 Jquery,我想知道是否有办法可以使用 Jquery 或 Javascript 来解决我的问题。
标签: javascript jquery html css navigation