jQuery打造漂亮的幻灯片效果

MrLee2017-10-17 1517

  幻灯片在互联网网站上随处可见,这个功能不仅可以更多,更好,更具有吸引力的展示你的产品,还可以给网站带来一种活力的效果。想想,整个网站全部是文字的话,那是多么的枯燥无味呢!网上这种资源一大堆,但是如果自己掌握这个技术,还可以自定义各种效果,岂不是快哉?

  下面就是一款jQuery写的幻灯片,代码非常少,实现原理也一目了然。

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <style type="text/css">
        /*重置浏览器默认样式*/
        
        html,
        body,
        ul,
        li,
        div,
        table,
        span,
        img {
            margin: 0px;
            padding: 0px;
        }
        
        html,
        body {
            margin: 0px;
            padding: 0px;
            height: 100%;
        }
        
        .slide_div {
            width: 100%;
            height: 100%;
        }
        
        .slide_img_div {
            position: relative;
        }
        
        .slide_img_ul {
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
        
        .slide_img_ul li img {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0px;
            top: 0px;
        }
        
        .slide_option {
            position: absolute;
            z-index: 999;
            bottom: 0px;
            width: 100%;
            background: black;
            opacity: 0.5;
            text-align: center;
            display: block;
            list-style: none;
        }
        
        .check_li {
            background: red !important;
            opacity: 1 !important;
        }
        
        .slide_option li {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: #f0f0f0;
            margin: 5px;
            display: inline-block;
            cursor: pointer;
        }
    </style>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
    <div id="" class="slide_div">
        <div id="slide_img_div">
            <div>
                <ul class="slide_img_ul">
                    <li><img src="1.png"></li>
                    <li><img src="2.png"></li>
                    <li><img src="3.png"></li>
                    <li><img src="4.png"></li>
                </ul>
                <ul class="slide_option">
                    <li class="check_li"></li>
                    <li class=""></li>
                    <li class=""></li>
                    <li class=""></li>
                </ul>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function() {
            $(".slide_img_ul li").hide();
            $(".slide_img_ul li").eq(0).show();
            $(".slide_option li").click(function() {
                var $check_li = $(this),
                    check_index = $(this).index();
                $check_li.addClass("check_li").siblings().removeClass("check_li");
                $(".slide_img_ul li").hide().eq(check_index).fadeToggle(500);
            })
            var ints = window.setInterval(Timers, 3000);
            function Timers() {
                var Allli = $(".slide_option li");
                var CheckLi = $(".slide_option .check_li"),
                    Cindex = Allli.index($(".slide_option .check_li"));
                if (Cindex + 1 == Allli.length) {
                    Allli.eq(0).trigger('click');
                } else {
                    CheckLi.next().trigger('click');
                }
            }
            $(".slide_option li").hover(function() {
                ints = window.clearInterval(ints);
            }, function() {
                ints = window.setInterval(Timers, 3000);
            })
        })
    </script>
</body>
</html>

你需要做的就是把 <li><img src="1.png"></li>中的图片换成你的图片或者直接把img标签换成你的div内容。看看效果图吧!

本文链接:https://www.it72.com/12266.htm

推荐阅读
最新回复 (0)
    返回