Day05(组件,轮播图插件)

组件,插件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            div{
                
            }
        </style>
    </head>
    <body>
        <div id="d1">我是一个div标签</div>

    </body>
    <script type="text/javascript" src="jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        jQuery.extend({
            "m":function(a){
                return a.width()+","+a.height();
            },
            
        });
        
        console.log($.m($("#d1")));
    </script>
</html>

demo 轮播图插件

<!DOCTYPE html>
<html lang="en">

    <head>
        <title></title>
        <meta charset="UTF-8">
        <script type="text/javascript" src="jquery-3.2.1.min.js"></script>
        <script type="text/javascript" src="banner.js"></script>
        <style type="text/css">
            ul {
                list-style: none;
            }
            
            .main {
                width: 1226px;
                height: 420px;
                position: relative;
                top: 0;
                left: 50%;
                margin-left: -613px;
            }
            
            .main_lb {
                position: relative;
                height: 460px;
                width: 1226px;
            }
            
            .lbk li {
                position: absolute;
                display: none;
            }
            
            .lbk li:nth-child(1) {
                display: block;
            }
            
            .btn_l {
                z-index: 10;
                position: absolute;
                left: 40px;
                top: 196px;
                height: 70px;
                width: 40px;
                background: url(img/lunbo/btn_l.png) no-repeat 2px 10px;
                border-radius: 0 2px 2px 0;
                background-color: rgba(0, 0, 0, 0);
                transition: 0.4s;
            }
            
            .btn_r {
                z-index: 10;
                position: absolute;
                right: -40px;
                top: 196px;
                height: 70px;
                width: 40px;
                background: url(img/lunbo/btn_r.png) no-repeat 2px 10px;
                border-radius: 2px 0 0 2px;
                background-color: rgba(0, 0, 0, 0);
                transition: 0.4s;
            }
            
            .btn_r:hover {
                background-color: rgba(0, 0, 0, 0.5);
                cursor: pointer;
            }
            
            .btn_l:hover {
                background-color: rgba(0, 0, 0, 0.5);
                cursor: pointer;
            }
            
            .btn_lis {
                list-style: none;
                position: absolute;
                right: 35px;
                top: 425px;
                z-index: 11;
            }
            
            .btn_lis li {
                float: left;
                height: 6px;
                width: 6px;
                border: 2px solid #acacac;
                border-radius: 8px;
                background: #666;
                margin-right: 10px;
                opacity: 0.6;
                cursor: pointer;
            }
            
            .btn_ls {
                background: #F5EBE0!important;
                border: 2px solid #666;
            }
        </style>
    </head>

    <body>
        <div class="main">
            <ul class="lbk">
                <li><img src="img/lunbo/lb1.jpg" /></li>
                <li><img src="img/lunbo/lb2.jpg" /></li>
                <li><img src="img/lunbo/lb3.jpg" /></li>
                <li><img src="img/lunbo/lb4.jpg" /></li>
                <li><img src="img/lunbo/lb5.jpg" /></li>
            </ul>
            <ul class="btn_lis">
                <li class="btn_ls"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
            <div class="btn_l"></div>
            <div class="btn_r"></div>
        </div>
    </body>
    <script type="text/javascript">
        $('.main').slider()
    </script>

</html>
(function($) {  
    $.fn.slider = function(options) {  
        //this指向当前的选择器  
        var config = {  
            index: 0,  
            timer: null,  
            speed: 3000,  
            min: 0.3, //和css中的样式对应  
            max: 1  
        };  
        var opts = $.extend(config, options);  
        //核心方法,把当前index的图片和icon显示,把除此之外的图片和icon隐藏  
        var core = function() {  
            if (opts.index > 4) {  
                opts.index = 0;  
            } else if (opts.index < 0) {  
                opts.index = 4;  
            }  
            $('.lbk').children().eq(opts.index).fadeIn(400).siblings('li').fadeOut(400);
            $('.btn_lis').children().eq(opts.index).addClass('btn_ls').siblings('li').removeClass('btn_ls');
        };  
        //左边  
        $(this).find(".btn_l").bind("click", function() {  
            --opts.index;  
            core();  
        });  
        //右边  
        $(this).find(".btn_r").bind("click", function() {  
            ++opts.index;  
            core();  
        });  
        //每个icon分配事件  
        $(this).find(".btn_lis").on("click", "li", function() {  
            var index = $(this).index();  
            opts.index = index;  
            core();  
        });  
        //定时器  
        var start = function() {  
            opts.timer = setInterval(function() {  
                ++opts.index;  
                core();  
            }, opts.speed);  
        }  
        $(this).hover(function() {  
            clearInterval(opts.timer);  
        }, function() {  
            start();  
        });  
        start();  
    }  
}(jQuery));  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一种新的协议。它实...
    香橙柚子阅读 24,146评论 8 183
  • 2016年11月17日,我们领听了
    花匠1阅读 226评论 0 0
  • 时至今日,微信已经由一个单纯的社交工具变成了主流的生活方式。工作群也越来越多的占领着每日聊天的页首位置。于是,朋友...
    蜜丝赵阅读 990评论 3 12
  • 他是将军遗孤,奉皇命驻守边疆,随时准备与敌决一死战。 她是桃村少女,扮成多病的弟弟,应征入伍忍受边疆苦寒。 战事已...
    安静的咖喱阅读 260评论 0 1
  • 一 (2014年7月毕业一年后重回北京,路过繁华的市中心,走到六环的落脚地,便是我工作和生活的地方。) 重返帝都 ...
    杜鹃阅读 578评论 3 3