您的位置:首页 > Web前端 > JQuery

jQuery 插件代码(收集)

2013-10-19 00:33 239 查看

为jQuery扩展wait方法 [jquery1.4之后添加该方法,但不同版本有不一样的写法]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>Wait插件演示</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
div { margin:3px; width:40px; height:40px; position:absolute; left:0px; top:30px; background:green; }
</style>
</head>
<body>
<div></div>
<script type="text/javascript">//<![CDATA[
$.fn.extend({
wait: function(time, type) {
return this.queue(type || "fx", function() {
var $this = $(this);
setTimeout(function() {$this.dequeue();}, time || 1000);
});
}
});
(function () {
$("div").wait()
.animate({left:'+=200'},2000)
.wait()
.animate({left:'-=200'},1500, arguments.callee);
})();
//]]></script>
</body>
</html>


View Code
jQuery.fn.delay

---1.4~1.6.4
function (time, type) {
time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
type = type || "fx";

return this.queue(type, function () {
var elem = this;
setTimeout(function () {
jQuery.dequeue(elem, type);
},
time);
});
}
---1.7.0以后
function (time, type) {
time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
type = type || "fx";

return this.queue(type, function (next, hooks) {
var timeout = setTimeout(next, time);
hooks.stop = function () {
clearTimeout(timeout);
};
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: