我想在我的导航滑块上添加两个按钮,这样我就可以来回走动。这样做最合适和最简单的方法是什么?将会感谢所提供的任何答案。
这是我的代码
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"/>
<title></title>
<link rel="stylesheet" href="stylesheet.css" type="text/css" media="all" />
<script type="text/javascript" src="jquery/jquery-1.2.6.min.js"></script>
<script src="jquery/slider.js"></script>
</head>
<body style="font-family: Arial, Sans-serif, sans;">
<h1>Slideshow</h1>
<div id="slideshow">
<img src="image1.jpg" alt="Slideshow Image 1" class="active" />
<img src="image2.jpg" alt="Slideshow Image 2" />
<img src="image3.jpg" alt="Slideshow Image 3" />
<img src="image4.jpg" alt="Slideshow Image 4" />
</div>
</body>
</html>
CSS
#slideshow {
position:relative;
height:350px;
}
#slideshow IMG {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
}
#slideshow IMG.active {
z-index:10;
opacity:1.0;
}
#slideshow IMG.last-active {
z-index:9;
}
Jquery的
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
$next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
答案 0 :(得分:2)
前进导航已经存在,您可以像以下一样使用它:
<a href="#" onclick="slideSwitch();return false;">next</a>
后退按钮与slideSwitch()函数相反:
function slideSwitchBack() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:first');
var $prev = $active.prev().length ? $active.prev() : $('#slideshow IMG:last');
$active.addClass('last-active');
$prev.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
上的演示