Giter Club home page Giter Club logo

jwait's Introduction

jWait

a jquery plugin ,which provide a easy way to delay your work

jquery(zepto)插件,把各种延迟串联起来,采用管道式写法 ----为了少写几个setTimeout,哈哈

安装

 npm install jwait

 bower install jWait

示例代码

原来 o(╯□╰)o

    setTimeout(function (){
        $('#b_1').addClass('active');
    },1000);

==> 现在 ^O^

    $('#b_1').jWait(1000)
             .addClass('active');

原来 o(╯□╰)o

    setTimeout(function (){
        $('#b_1').addClass('active');
        
        setTimeout(function (){
            $('#b_2').css({color:red});
        },1000);
    },1000);

==> 现在 ^O^

    $('#b_1').jWait(1000)
             .addClass('active')
             .jWait(1000)
             .jWait('#b_2').css({color:red});

原来 o(╯□╰)o

    function doSth(){
        //...
    }

    setTimeout(function (){
        $('#b_1').addClass('active');
        doSth();
        setTimeout(function (){
            doSth();
            $('#b_2').css({color:red});
        },1000);
    },1000);

==> 现在 ^O^

    function doSth(){
        //...
    }   
    
    $('#b_1').jWait(1000)
             .addClass('active')
             .jWait(doSth)
             .jWait(1000)
             .jWait(doSth)
             .jWait('#b_2').css({color:red});

简单图解

     
    $('#b_1').jWait(1000)
             .addClass('active') //$('#b_1').addClass('active')
             .jWait(1000)
             .fadeIn() //$('#b_1').fadeIn()
             
             .jWait('#b_2')//修改代理的对象为 $('#b_2')
             .jWait(1000)
             .css({color:'red'})//$('#b_2').css({color:'red'})
             .jWait(function (){
                //这里获取当前代理对象 this ==> $('#b_2')
                console.log(this.css('color'));
             })
             
             .jWait(console)//修改代理的对象为 console
             .log('hello') //console.log('hello') 
             .error('error');//console.error('error');
              

参数

/**
 *
 * @param waitObj  绑定对象可以是 (数字,字符串,对象,方法)
 * 1.数字 表示延迟的时间(单位:毫秒)
 * 2.字符串 查询字符串querySelector,表示切换代理的对象为查询字符串代表的jquery对象
 * 3.对象 代理的对象,表示切换代理的对象
 * 4.方法 延迟后执行的函数,如果没有延迟,则直接执行
 *
 * @param callback 回调方法,只有当waitObj是数字类型时有效
 * @returns {jWaitProxy} 返回一个执行代理对象,一个神奇的对象
 */
$.fn.jWait = function (waitObj, callback) {
//....
}

jwait's People

Contributors

justinzzc avatar

Stargazers

desbest avatar 风起兮 avatar

Watchers

James Cloos avatar  avatar 风起兮 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.