$.fn.retarder = function(delay, method) {
var node = this;
if (node.length) {
if (node[0]._timer_) clearTimeout(node[0]._timer_);
node[0]._timer_ = setTimeout(function() {
method(node);
},
delay);
}
return this;
};

原理就是用了setTimeout这函数, 使用方法

            $(div).retarder(150,
function(i) {
box.css({
height: box[0].hei - 50,
width: box[0].wid,
overflow: 'hidden'
});
i.css(animate.from).stop(true, true).animate(animate.to, {
duration: 200,
complete: function() {
if (!$.browser.msie) div.css('opacity', 1);
box.css('display', 'none')
}
})
})

使用实例基于缓冲器做成的图片轮播渐显插件如下:

HTML

                <div>
<img src="/images/1.png" />
</div>
<div>
<img src="/images/2.png" />
</div>
<div>
<img src="/images/3.png" />
</div>
<div>
<img src="/images/4.png" />
</div>
<div>
<img src="/images/5.png" />
</div>
</div>

jQuery

        $.fn.initSlideshow = function () {
var self = $(this);
self.find("div").each(function (n) {
var This = $(this);
This.retarder(n * 2000, function (node) {
node.fadeIn(1000, function () {
if (n == self.find("div").length - 1) {
/*self.find("div").fadeOut(1000).retarder(2000, function (node) {
node.fadeIn(1000);
});*/
self.find("div").retarder(5000, function (node) {
node.fadeOut(1000);
});
self.retarder(7000, function (node) {
node.initSlideshow();
});
}
});
});
});
};

CSS

        #slideshow {
width: 1040px;
height: 345px;
padding-left: 10px;
} #slideshow div {
float: left;
height: 345px;
line-height: 345px;
display: none;
}

简单的jQuery扩展函数-让函数缓冲执行的更多相关文章

  1. jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...

    写了一个html,用到了jQuery,发现没有按照预期的结果显示,最后定位到是$.get()函数没有运行 调试过程为: 在页面右击查看元素,到网络那一栏,找到类型为json的那个包点击,然后查看响应, ...

  2. Jquery ajax回调函数不执行

    ajax如下: $.post( "${pageContext.request.contextPath}/deptHead_assign.action", {"studen ...

  3. js、jquery的入口函数及其执行与图片加载的先后顺序

    js的入口函数写法: window.onload = function() { }; 如果文件中有多个window.onload入口函数,则只会执行最后一个,之前的入口函数没有用. jquery的入口 ...

  4. jQuery源码,匿名函数自执行

    jQuery框架的首尾是这样写的()(), (function(window){//这个window是个入参,随便起个名字都行 //这里面全都是js代码 })(window)//这个括号里的windo ...

  5. 使用jquery移除前面通过onclick绑定的元素的事件,然后重新绑定别的函数来执行onclick事件。

    http://caibaojian.com/css3/experience/bugs.htm 使用jquery移除前面通过onclick绑定的元素的事件,然后重新绑定别的函数来执行onclick事件. ...

  6. 关于jQuery中toggle参数callback函数提前执行问题

    通过 jQuery,您可以使用 toggle() 方法来切换 hide() 和 show() 方法. 显示被隐藏的元素,并隐藏已显示的元素: $(selector).toggle(speed,call ...

  7. jQuery - 1.简单的JQuery

    1.简单的JQuery 2.jQuery对象(包装集).Dom对象 3.JQuery提供的函数 1.简单的JQuery $(document).ready(function () { alert(&q ...

  8. jQuery Ajax 操作函数及deferred对象

    jQuery Ajax 操作函数 jQuery 库拥有完整的 Ajax 兼容套件.其中的函数和方法允许我们在不刷新浏览器的情况下从服务器加载数据. 函数 描述 jQuery.ajax() 执行异步 H ...

  9. 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()

    一,$.get(url,[data],[callback]) 说明:url为请求地址,data为请求数据的列表(是可选的,也可以将要传的参数写在url里面),callback为请求成功后的回调函数,该 ...

随机推荐

  1. 数据结构One_Vector(向量的简单实现)

    #include <iostream> using namespace std; template<typename Object> class Vector { privat ...

  2. SQL Server多表多列更新

    student表: lag表: 要求将student表stu_id列为1的stu_nick列和stu_phont列的数据更新为lag表的lag_nick列和lag_phone列. SQL语句: upd ...

  3. XMPP框架下微信项目总结(2)授权登陆/注销/注册/打印日志

    xmpp授权登陆步骤1 初始化xmppstream 连接服务器 传递属性jid(IP地址 端口号)2 连接成功后 传递“登”陆密码授权 3 授权后,发送在线消息xmpp所有的代理都是子线程中调用的,处 ...

  4. 素数环(dfs+回溯)

    题目描述: 输入正整数n,把整数1,2...n组成一个环,使得相邻两个数和为素数.输出时从整数1开始逆时针排列并且不能重复: 例样输入: 6 例样输出: 1 4 3 2 5 6 1 6 5 2 3 4 ...

  5. Retrofit与RXJava整合

    Retrofit 除了提供了传统的 Callback 形式的 API,还有 RxJava 版本的 Observable 形式 API.下面我用对比的方式来介绍 Retrofit 的 RxJava 版 ...

  6. hdu 1279 验证角谷猜想

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1279 #include<stdlib.h> #include<time.h> ...

  7. js获取url方法

    //设置或获取对象指定的文件名或路径.alert(window.location.pathname); //设置或获取整个 URL 为字符串.alert(window.location.href); ...

  8. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- Messenger

    Messenger类实际是对Aidl方式的一层封装.本文只是对如何在Service中使用Messenger类实现与客户端的通信进行讲解,对Messenger的底层不做说明.阅读Android Prog ...

  9. nc 显示服务器开放的端口

    # nc -z -w xxxx.com - Connection to xxxx.com port [tcp/ftp] succeeded! Connection to xxxx.com port [ ...

  10. js获取url参数值(HTML之间传值)

    <h3>未设置设备: <a href="javascript:addTab('设备列表','PKE_DeviceContent/PKE_DeviceContent.aspx ...