0
我创建了一个非常类似于http://themeforest.s3.amazonaws.com/116_parallax/tutorial-source-files/tut-index.html的网站。现在我想添加关键导航。所以当我向右推箭头时,它会转到box2,当箭头离开时返回到Home。 我想这个教程http://jqueryfordesigners.com/adding-keyboard-navigation/键盘导航JQuery
所以:
$().ready(function() {
$(document.documentElement).keyup(function (event) {
var direction = null;
// handle cursor keys
if (event.keyCode == 37) {
// go left
direction = 'prev';
} else if (event.keyCode == 39) {
// go right
direction = 'next';
}
if (direction != null) {
$('.coda-slider-wrapper ul a#current').parent()[direction]().find('a').click();
}
});
});
而且
<div id="header" class="coda-slider-wrapper">
<h1 id="logo">Scrolling Clouds</h1>
<ul id="menu">
<li><a href="#box1" class="link" id="current">Home</a></li>
<li><a href="#box2" class="link">Box 2</a></li>
<li><a href="#box3" class="link">Box 3</a></li>
<li><a href="#box4" class="link">Box 4</a></li>
</ul>
</div>
偏偏它不会becouse只有一个elemnt正常工作具有ID = “电流”。 如何让它工作?如何添加动态ID?请给我写下所有的代码。
THX的帮助。