繁体   English   中英

图像滑块导航按钮

[英]image slider navigation buttons

我想在我的导航滑块上添加两个按钮,这样我就可以来回走动。 这样做最合适和最简单的方法是什么? 将欣赏提供的任何答案。

这是我的代码

<!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 );
});

前进导航已经存在,你可以使用它:

<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');
        });
}

请参阅http://jsfiddle.net/zuY5H/上的演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM