h var swiper = function() {
// $('img').eq(index).stop().animate({ 'opacity': 1 }, 500).siblings().stop().animate({ 'opacity': 0 }, 500);
$('img').eq(index).stop().fadeIn(500).siblings().stop().fadeOut(500);
$('a').eq(index).css({ 'color': 'red' }).siblings().css({ 'color': '#255d7e' });
}
$(document).on('mouseenter', 'a', function() {
// $('img').eq($(this).index()).stop().animate({ 'opacity': 1 }, 500).siblings().stop().animate({ 'opacity': 0 }, 500);
$('img').eq($(this).index()).stop().fadeIn(500).siblings().stop().fadeOut(500);
$('a').eq($(this).index()).css({ 'color': 'red' }).siblings().css({ 'color': '#255d7e' });
});
var index = 0;
$(document).on('keyup', function() {
if (event.keyCode == 37) {
index--;
if (index < 0) {
index = $('img').length - 1;
}
swiper();
}
if (event.keyCode == 39) {
index++;
if (index == $('img').length) {
index = 0;
}
swiper();
}
console.log(index);
});
var start = function() {
index = 0;
swiper();
}
start();
JS的代码如上,麻烦您看下吧