jQuery动画
分类:
IT文章
•
2023-11-17 08:05:42
show()和hide()—隐藏显示
//show()和hide() hide()首先记住display的值,在将display设置为None
$(function () {
$("#panel h5.head").toggle(function () {
$(this).next("div.content").hide(600);
}, function () {
$(this).next("div.content").show(600);
});
});
View Code
fadeOut()和fadeIn()—通过不透明度隐藏或显示
//fadeOut() 降低元素的不透明度
//fadeIn() 与fadeOut()相反
$(function () {
$("#panel h5.head").mousemove(function () {
$(this).next("div.content").fadeOut();
}).mouseout(function () {
$(this).next("div.content").fadeIn();
});
})
View Code
slideDown()和slideUp()—改变元素高度,向下延深,向上收缩
//slideDown() 改变元素高度 元素由上至下延伸显示
//slideUp() 由下到上收缩
$(function () {
$("#panel h5.head").toggle(function () {
$(this).next("div.content").slideUp();
}, function () {
$(this).next("div.content").slideDown();
});
});
View Code
$(function () {
$("#panel1").css("opacity", "0.5"); //设置不透明度
$("#panel1").click(function () {
$(this).animate({ left: "500px" }, 3000); //以3秒的速度移动
$(this).animate({ left: "+=500px" }, 3000); //以3秒的速度累加移动
$(this).animate({ left: "-=500px" }, 3000); //以3秒的速度累减移动
//多种效果动画,改变样式映射
$(this).animate({ left: "500px", height: "200px" }, 3000); //向右下方移动同步移动
//多种效果可以有序的执行
$(this).animate({ left: "500px" }, 3000);
$(this).animate({ height: "200px" }, 3000);
//可改为链式:
$(this).animate({ left: "500px" }, 3000)
.animate({ height: "200px" }, 2000);
//综合动画
$(this).animate({ left: "400px", height: "200px", opacity: "1" }, 3000)
.animate({ top: "200px", "200px" }, 3000, function () {
$(this).css("border", "5px solid blue");
})
.fadeOut("slow");
})
})