标签:
本文以实例形式详细讲述了jQuery动画特效的实现方法。
1.自制折叠内容块
内容块如下:
< div class = "module" > < div class = "caption" > < span >标题</ span > < img src = "rollup.gif" alt = "rollup" title = "rolls up this module" /> </ div > < div class = "body" > 春江彼岸两大明星产品之一:超越型复式,在春江郦城97复式基础上再升级,终点: </ div > </ div > |
给img元素绑定点击事件。
$(
function
() {
$(
‘div.caption img‘
).click(
function
() {
//先找到img的父级元素,再找该父级元素的子元素
var
$body = $(
this
).closest(
‘div.module‘
).find(
‘div.body‘
);
if
($body.is(
‘:hidden‘
)) {
$body.show();
}
else
{
$body.hide();
}
});
});
$(
function
() {
$(
‘div.caption img‘
).click(
function
() {
$(
this
).closest(
‘div.module‘
).find(
‘div.body‘
).toggle();
});
});
$(
function
() {
$(
‘div.caption img‘
).click(
function
() {
$(
this
).closest(
‘div.module‘
).find(
‘div.body‘
).toggle(
‘slow‘
);
});
});
$(
function
() {
$(
‘div.caption img‘
).click(
function
() {
$(
this
).closest(
‘div.module‘
).find(
‘div.body‘
).toggle(
‘slow‘
,
function
() {
$(
this
).closest(
‘div.module‘
).toggleClass(
‘rolledup‘
, $(
this
).is(
‘:hidden‘
))
});
});
});
fadeIn(speed, callback)
fadeOut(speed, callback)
fadeTo(speed, opacity, callback)
slideDown(speed, callback)
slideUp(speed, callback)
slideToggle(speed, callback)
stop(clearQueue, gotoEnd)
animate(properties, duration, easing, callback)
$(
‘.classname‘
).animate({opacity:
‘toggle‘
},
‘slow‘
)
$.fn.fadeToggle =
function
(speed){
return
this
.animate({opacity:
‘toggle‘
},
‘slow‘
);
}
$(
‘.classname‘
).each(
function
(){
$(
this
).animate({
width: $(
this
).width() * 2,
height: $(
this
).height() * 2
});
});
$(
‘.classname‘
).each(
function
(){
$(
this
)
.css(
"position"
,
"relative"
)
.animate({
opacity: 0,
top: $(window).height() - $(
this
).height() - $(
this
).position().top
},
‘slow‘
,
function
(){ $(
this
).hide(); })
});
$(
‘.classname‘
).each(
function
(){
var
position = $(
this
).position();
$(
this
)
.css({
position:
‘absolute‘
,
top: position.top,
left:position.left
})
.animate({
opacity:
‘hide‘
,
width: $(
this
).width()*5,
height: $(
this
).height()*5
top: position.top - ($(
this
).height() * 5 / 2),
left: position.left - ($(
this
).width() * 5 /2)
},
‘normal‘
);
});
//动画插入队列
$(
‘img‘
).queue(
‘chain‘
,
function
(){});
$(
‘img‘
).queue(
‘chain‘
,
function
(){});
$(
‘img‘
).queue(
‘chain‘
,
function
(){});
$(
‘img‘
).queue(
‘chain‘
,
function
(){});
$(
‘button‘
).click(
function
(){
$(
‘img‘
).dequeue(
‘chain‘
);
//删除队列中的动画
})
cleaeQueue(name)
//删除所有未执行的队列中的动画
delay(duration, name)
//为队列中所有未执行的动画添加延迟
标签:
原文地址:http://www.cnblogs.com/zexian/p/5823315.html