CSS+jQuery實(shí)現(xiàn)的一個(gè)放大縮小動(dòng)畫(huà)效果
更新時(shí)間:2013年09月24日 11:35:16 作者:
因?yàn)樾枨缶椭挥?個(gè)元素。如果是要用CSS的class來(lái)處理,那就需要用到CSS3動(dòng)畫(huà)了,好了下面為大家介紹下如何實(shí)現(xiàn)這個(gè)放大縮小動(dòng)畫(huà)效果
今天幫朋友寫(xiě)了一些代碼,自己覺(jué)得寫(xiě)著寫(xiě)著,好幾個(gè)版本以后,有點(diǎn)滿意,于是就貼出來(lái)。
都是定死了的。因?yàn)樾枨缶椭挥?個(gè)元素。如果是要用CSS的class來(lái)處理,那就需要用到CSS3動(dòng)畫(huà)了。
<!DOCTYPE html>
<html>
<head>
<title> CSS+jQuery動(dòng)畫(huà)效果 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="鐵錨">
<style>
body{
z-index: 0;
width: 100%;
min-height: 400px;
}
.pages{
position: absolute;
}
.current{
position: absolute;
z-index: 12 !important;
left: 0px !important;
}
.page1{
background-color: #a5cfff;
z-index: 1;
width: 300px;
height:280px;
top: 100px;
left: 0px;
}
.page2{
background-color: #b1ca54;
z-index: 2;
width: 250px;
height:270px;
top: 160px;
left: 0px;
}
.page3{
background-color: #c2c6c9;
z-index: 3;
width: 200px;
height:260px;
top: 220px;
left: 0px;
}
.page4{
background-color: #ef9e9c;
z-index: 4;
width: 150px;
height:250px;
top: 250px;
left: 0px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
// 增長(zhǎng)
function increase($div,e){
var style = $div.attr("style");
$div.addClass("current").attr("styleold",style);
//
$div.stop();
$div.animate({
opacity:0.9,
width:"400px",
height: "400px",
top: "100px",
left: "0px"
},600)
.animate({
opacity:1.0
},30);
e.stopPropagation();
return false;
};
// 還原
function resize(e){
// 所有的都移除
var $page1 = $(".current.page1") ;
$page1.stop();
$page1.animate({
opacity:1.0,
width:"300px",
height: "280px",
top: "100px",
left: "0px"
},600,null,function(){
$page1.removeClass("current").attr("style","");
});
var $page2 = $(".current.page2") ;
$page2.stop();
$page2.animate({
opacity:1.0,
width:"250px",
height: "270px",
top: "160px",
left: "0px"
},600,null,function(){
$page2.removeClass("current").attr("style","");
});
var $page3 = $(".current.page3") ;
$page3.stop();
$page3.animate({
opacity:1.0,
width:"200px",
height: "260px",
top: "220px",
left: "0px"
},600,null,function(){
$page3.removeClass("current").attr("style","");
});
var $page4 = $(".current.page4") ;
$page4.stop();
$page4.animate({
opacity:1.0,
width:"150px",
height: "250px",
top: "250px",
left: "0px"
},600,null,function(){
$page4.removeClass("current").attr("style","");
});
e.stopPropagation();
return false;
};
//
$("#button1").unbind("mouseover").bind("mouseover",function(e){
//
var $page1 = $(".page1");
// 添加特定的
return increase($page1,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$("#button2").unbind("mouseover").bind("mouseover",function(e){
//
var $page2 = $(".page2");
// 添加特定的
return increase($page2,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$("#button3").unbind("mouseover").bind("mouseover",function(e){
//
var $page3 = $(".page3");
// 添加特定的
return increase($page3,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$("#button4").unbind("mouseover").bind("mouseover",function(e){
//
var $page4 = $(".page4");
// 添加特定的
return increase($page4,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$(".pages").unbind("mouseover").bind("mouseover",function(e){
//
var $this = $(this);
// 添加特定的
return increase($this,e);
}).unbind("mouseout").bind("mouseout",function(e){
// 所有的都移除
return resize(e);
});
//
$("body").click(function(e){
// 所有的都移除
return resize(e);
});
});
</script>
</head>
<body>
<div class="pages page1">page1</div>
<div class="pages page2">page2</div>
<div class="pages page3">page3</div>
<div class="pages page4">page4</div>
<div style="background-color: #a5cfff;">
<button id="button1">第一頁(yè)</button>
<button id="button2">第2頁(yè)</button>
<button id="button3">第3頁(yè)</button>
<button id="button4">第4頁(yè)</button>
</div>
</body>
</html>
都是定死了的。因?yàn)樾枨缶椭挥?個(gè)元素。如果是要用CSS的class來(lái)處理,那就需要用到CSS3動(dòng)畫(huà)了。
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<title> CSS+jQuery動(dòng)畫(huà)效果 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="鐵錨">
<style>
body{
z-index: 0;
width: 100%;
min-height: 400px;
}
.pages{
position: absolute;
}
.current{
position: absolute;
z-index: 12 !important;
left: 0px !important;
}
.page1{
background-color: #a5cfff;
z-index: 1;
width: 300px;
height:280px;
top: 100px;
left: 0px;
}
.page2{
background-color: #b1ca54;
z-index: 2;
width: 250px;
height:270px;
top: 160px;
left: 0px;
}
.page3{
background-color: #c2c6c9;
z-index: 3;
width: 200px;
height:260px;
top: 220px;
left: 0px;
}
.page4{
background-color: #ef9e9c;
z-index: 4;
width: 150px;
height:250px;
top: 250px;
left: 0px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
// 增長(zhǎng)
function increase($div,e){
var style = $div.attr("style");
$div.addClass("current").attr("styleold",style);
//
$div.stop();
$div.animate({
opacity:0.9,
width:"400px",
height: "400px",
top: "100px",
left: "0px"
},600)
.animate({
opacity:1.0
},30);
e.stopPropagation();
return false;
};
// 還原
function resize(e){
// 所有的都移除
var $page1 = $(".current.page1") ;
$page1.stop();
$page1.animate({
opacity:1.0,
width:"300px",
height: "280px",
top: "100px",
left: "0px"
},600,null,function(){
$page1.removeClass("current").attr("style","");
});
var $page2 = $(".current.page2") ;
$page2.stop();
$page2.animate({
opacity:1.0,
width:"250px",
height: "270px",
top: "160px",
left: "0px"
},600,null,function(){
$page2.removeClass("current").attr("style","");
});
var $page3 = $(".current.page3") ;
$page3.stop();
$page3.animate({
opacity:1.0,
width:"200px",
height: "260px",
top: "220px",
left: "0px"
},600,null,function(){
$page3.removeClass("current").attr("style","");
});
var $page4 = $(".current.page4") ;
$page4.stop();
$page4.animate({
opacity:1.0,
width:"150px",
height: "250px",
top: "250px",
left: "0px"
},600,null,function(){
$page4.removeClass("current").attr("style","");
});
e.stopPropagation();
return false;
};
//
$("#button1").unbind("mouseover").bind("mouseover",function(e){
//
var $page1 = $(".page1");
// 添加特定的
return increase($page1,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$("#button2").unbind("mouseover").bind("mouseover",function(e){
//
var $page2 = $(".page2");
// 添加特定的
return increase($page2,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$("#button3").unbind("mouseover").bind("mouseover",function(e){
//
var $page3 = $(".page3");
// 添加特定的
return increase($page3,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$("#button4").unbind("mouseover").bind("mouseover",function(e){
//
var $page4 = $(".page4");
// 添加特定的
return increase($page4,e);
}).unbind("mouseout").bind("mouseout",function(e){
return resize(e);
});
//
$(".pages").unbind("mouseover").bind("mouseover",function(e){
//
var $this = $(this);
// 添加特定的
return increase($this,e);
}).unbind("mouseout").bind("mouseout",function(e){
// 所有的都移除
return resize(e);
});
//
$("body").click(function(e){
// 所有的都移除
return resize(e);
});
});
</script>
</head>
<body>
<div class="pages page1">page1</div>
<div class="pages page2">page2</div>
<div class="pages page3">page3</div>
<div class="pages page4">page4</div>
<div style="background-color: #a5cfff;">
<button id="button1">第一頁(yè)</button>
<button id="button2">第2頁(yè)</button>
<button id="button3">第3頁(yè)</button>
<button id="button4">第4頁(yè)</button>
</div>
</body>
</html>
您可能感興趣的文章:
- 基于Jquery和html5實(shí)現(xiàn)炫酷的3D焦點(diǎn)圖動(dòng)畫(huà)
- jquery+html5爛漫愛(ài)心表白動(dòng)畫(huà)代碼分享
- jQuery結(jié)合HTML5制作的愛(ài)心樹(shù)表白動(dòng)畫(huà)
- jQuery實(shí)現(xiàn)加入購(gòu)物車(chē)飛入動(dòng)畫(huà)效果
- jQuery實(shí)現(xiàn)圖像旋轉(zhuǎn)動(dòng)畫(huà)效果
- JQuery動(dòng)畫(huà)和停止動(dòng)畫(huà)實(shí)例代碼
- Jquery中使用show()與hide()方法動(dòng)畫(huà)顯示和隱藏圖片
- jQuery下的動(dòng)畫(huà)處理總結(jié)
- 基于jquery的direction圖片漸變動(dòng)畫(huà)效果
- jQuery+HTML5實(shí)現(xiàn)WebGL高性能煙花綻放動(dòng)畫(huà)效果【附demo源碼下載】
相關(guān)文章
Jquery通過(guò)Ajax訪問(wèn)XML數(shù)據(jù)的小例子
這篇文章主要介紹了Jquery通過(guò)Ajax訪問(wèn)XML數(shù)據(jù),有需要的朋友可以參考一下2013-11-11
jQuery插件zTree實(shí)現(xiàn)的基本樹(shù)與節(jié)點(diǎn)獲取操作示例
這篇文章主要介紹了jQuery插件zTree實(shí)現(xiàn)的基本樹(shù)與節(jié)點(diǎn)獲取操作,結(jié)合實(shí)例形式分析了jQuery樹(shù)形插件zTree構(gòu)造基本樹(shù)與針對(duì)節(jié)點(diǎn)的獲取操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-03-03
jquery的extend和fn.extend的使用說(shuō)明
jQuery.fn.extend(object); 對(duì)jQuery.prototype進(jìn)得擴(kuò)展,就是為jQuery類(lèi)添加“成員函數(shù)”。jQuery類(lèi)的實(shí)例可以使用這個(gè)“成員函數(shù)”。2011-01-01
jquery+swiper組件實(shí)現(xiàn)時(shí)間軸滑動(dòng)年份tab切換效果
這篇文章主要介紹了jquery+swiper組件實(shí)現(xiàn)時(shí)間軸滑動(dòng)年份tab切換效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12
詳解jQuery的表單驗(yàn)證插件--Validation
jQuery Validate 插件為表單提供了強(qiáng)大的驗(yàn)證功能,讓客戶(hù)端表單驗(yàn)證變得更簡(jiǎn)單,同時(shí)提供了大量的定制選項(xiàng),滿足應(yīng)用程序各種需求。本文主要對(duì)表單驗(yàn)證插件-Validation進(jìn)行案例分析,詳細(xì)介紹,具有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧2016-12-12
JQuery拖拽元素改變大小尺寸實(shí)現(xiàn)代碼
"元素拖拽改變大小"其實(shí)和"元素拖拽"一個(gè)原理,以下附出源碼原型,弄明白了原理再擴(kuò)展其他實(shí)際應(yīng)用,思路就變得簡(jiǎn)單、清晰得多了2012-12-12

