結構-行為-樣式-requireJs實現圖片輪播外掛程式

來源:互聯網
上載者:User

標籤:

最近工作需要,就自己寫了一個圖片輪播外掛程式,不過想到要整合到架構中,於是又用RequireJs改了一遍。

主要檔案:
  • style.css
  • jquery-1.11.1.min.js
  • require.js
  • viewpager.js
  • view.js
  • index.html

viewpager.js:

 

define([‘jquery‘], function ($) {    function ViewPager(setting) {        var myset = {            index: 0        };        setting = $.extend({}, myset, setting);        this.init(setting);    };    ViewPager.prototype = {        init: function (s) {            this.id = s.id;            this.list = $("#" + s.id).find("li");            this.index = s.index;            this.isAuto = s.isAuto;            this.renderUI();            this.bindUI();        }        , renderUI: function () {            var inHtml = $(‘<div class="prev"><span class="prev_icon"></span></div><div class="next"><span class="next_icon"></span></div>‘);            //選取器到指定的ID            //inHtml.appendTo("body ul#viewpager");            $("#" + this.id).append(inHtml);        }        , bindUI: function () {            var that = this;            if (that.isAuto) {                setInterval(function () {                    that.prev();                }, 3000);            }            $("#" + this.id).delegate(".prev", "click", function () {                that.prev();            });            $("#" + this.id).delegate(".next", "click", function () {                that.next();            });        }        , prev: function () {            $(this.list[this.index]).animate({                opacity: ‘hide‘            }, 500);            if (this.index < this.list.length - 1) {                this.index++;                this.picgo();            }            else {                this.index = 0;                this.picgo();            }        }        , next: function () {            $(this.list[this.index]).animate({                opacity: ‘hide‘            }, 500);            if (this.index > 0) {                this.index--;                this.picgo();            }            else {                this.index = this.list.length - 1;                this.picgo();            }        }        , picgo: function () {            $(this.list[this.index]).css({                "left": "0px"            });            $(this.list[this.index]).animate({                opacity: ‘show‘            }, 800);        }    };    return {        ViewPager: ViewPager    }});

 

 

 

view.js

 

require.config({    paths: {        "jquery": "js/jquery-1.11.1.min"        , "viewpager": "js/viewpager"        , "abstract": "js/abstract"    }});require([‘jquery‘, ‘viewpager‘], function ($, v) {    new v.ViewPager({        "id": "viewpager"        , "isAuto": true    });    new v.ViewPager({        "id": "viewpager1"    });});

 

 

index.html

 

<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <title>Component Learn</title>    <link rel="stylesheet" href="http://mj-staples.blog.163.com/blog/css/style.css" type="text/css"> </head><body>    <div class="view-main">        <ul id="viewpager">            <li class="active"><img src="http://mj-staples.blog.163.com/blog/img/0.jpg" alt="0.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/1.jpg" alt="1.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/2.jpg" alt="2.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/3.jpg" alt="3.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/4.jpg" alt="4.jpg" /></li>        </ul>    </div>    <hr>    <div class="view-main">        <ul id="viewpager1">            <li class="active"><img src="http://mj-staples.blog.163.com/blog/img/0.jpg" alt="0.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/1.jpg" alt="1.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/2.jpg" alt="2.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/3.jpg" alt="3.jpg" /></li>            <li><img src="http://mj-staples.blog.163.com/blog/img/4.jpg" alt="4.jpg" /></li>        </ul>    </div>    <script type="text/javascript" data-main="view" src="http://mj-staples.blog.163.com/blog/js/require.js"></script></body></html>

 

結構-行為-樣式-requireJs實現圖片輪播外掛程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.