一个CSS+jQuery实现的放大缩小动画效果


Posted in Javascript onFebruary 19, 2014

今天帮朋友写了一些代码,自己觉得写着写着,好几个版本以后,有点满意,于是就贴出来。

都是定死了的。因为需求就只有4个元素。如果是要用CSS的class来处理,那就需要用到CSS3动画了。

功能 : 在上方的按钮上滑动,可以切换各个page,点击下方的各个page,也可以切换收缩还是展开状态。
一个CSS+jQuery实现的放大缩小动画效果 
初始效果预览

<!DOCTYPE html> 
<html> 
<head> 
<title> CSS+jQuery动画效果 </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(){ 
// 增长 
function increase($div,e){ 
var expstatus = $div.data("expstatus"); 
if(!expstatus){ 
// 没有展开过 
$div.data("expstatus","yes"); 
} 
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",""); 
}); 
// 
var expstatus1 = $page1.data("expstatus"); 
if(expstatus1){ 
$page1.data("expstatus",null); 
} 
var expstatus2 = $page2.data("expstatus"); 
if(expstatus2){ 
$page2.data("expstatus",null); 
} 
var expstatus3 = $page3.data("expstatus"); 
if(expstatus3){ 
$page3.data("expstatus",null); 
} 
var expstatus4 = $page4.data("expstatus"); 
if(expstatus4){ 
$page4.data("expstatus",null); 
} 
if(e){ 
e.stopPropagation(); 
return false; 
} else { 
return true; 
} 
}; 
// 
$("#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); 
}); 
// 新的 
$(".pages").unbind("click touchstart").bind("click touchstart",function(e){ 
// 
var $this = $(this); 
var expstatus = $this.data("expstatus"); 
if(!expstatus){ 
// 没有展开过 
// 
return increase($this,e); 
} else { 
return resize(e); 
} 
}); 
// 
$("body").click(function(e){ 
// 所有的都移除 
return resize(null); 
}); 
}); 
</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">第一页</button> 
<button id="button2">第2页</button> 
<button id="button3">第3页</button> 
<button id="button4">第4页</button> 
</div> 
</body> 
</html>
Javascript 相关文章推荐
获取网站跟路径的javascript代码(站点及虚拟目录)
Oct 20 Javascript
Array 重排序方法和操作方法的简单实例
Jan 24 Javascript
jQuery中:reset选择器用法实例
Jan 04 Javascript
基于jquery实现表格内容筛选功能实例解析
May 09 Javascript
js中获取jsp表单中radio类型的值简单实例
Aug 15 Javascript
前端js实现文件的断点续传 后端PHP文件接收
Oct 14 Javascript
jQuery+HTML5实现弹出创意搜索框层
Dec 29 Javascript
详解用函数式编程对JavaScript进行断舍离
Sep 18 Javascript
vue+springboot前后端分离实现单点登录跨域问题解决方法
Jan 30 Javascript
JavaScript中Object基础内部方法图
Feb 05 Javascript
Vue 实现拖动滑块验证功能(只有css+js没有后台验证步骤)
Aug 24 Javascript
bootstrap table列和表头对不齐的解决方法
Jul 19 Javascript
使用CSS样式position:fixed水平滚动的方法
Feb 19 #Javascript
jQuery拖拽div实现思路
Feb 19 #Javascript
JQuery异步加载无限下拉框级联功能实现示例
Feb 19 #Javascript
调用DOM对象的focus使文本框获得焦点
Feb 19 #Javascript
让jQuery Mobile不显示讨厌loading界面的方法
Feb 19 #Javascript
javascript动态向网页中添加表格实现代码
Feb 19 #Javascript
javascript实现动态侧边栏代码
Feb 19 #Javascript
You might like
php对象和数组相互转换的方法
2015/05/12 PHP
Centos PHP 扩展Xchche的安装教程
2016/07/09 PHP
ExtJS 2.0实用简明教程之应用ExtJS
2009/04/29 Javascript
jquery更换文章内容与改变字体大小代码
2013/09/30 Javascript
css样式标签和js语法属性区别
2013/11/06 Javascript
js获取客户端外网ip的简单实例
2013/11/21 Javascript
日常收集整理的JavaScript常用函数方法
2015/12/10 Javascript
JS动态增删表格行的方法
2016/03/03 Javascript
如何用JavaScript实现动态修改CSS样式表
2016/05/20 Javascript
第一次接触神奇的Bootstrap表单
2016/07/27 Javascript
JQ中$(window).load和$(document).ready区别与执行顺序
2017/03/01 Javascript
Angular.js初始化之ng-app的自动绑定与手动绑定详解
2017/07/31 Javascript
使用Dropzone.js上传的示例代码
2017/10/10 Javascript
Angular如何在应用初始化时运行代码详解
2018/06/11 Javascript
浅析vue.js数组的变异方法
2018/06/30 Javascript
vue中Axios的封装与API接口的管理详解
2018/08/09 Javascript
python获取豆瓣电影简介代码分享
2014/01/16 Python
python支持断点续传的多线程下载示例
2014/01/16 Python
Flask框架配置与调试操作示例
2018/07/23 Python
Python3标准库总结
2019/02/19 Python
Python制作微信好友背景墙教程(附完整代码)
2019/07/17 Python
django删除表重建的实现方法
2019/08/28 Python
python数据库开发之MongoDB安装及Python3操作MongoDB数据库详细方法与实例
2020/03/18 Python
Eclipse配置python默认头过程图解
2020/04/26 Python
python3 循环读取excel文件并写入json操作
2020/07/14 Python
使用tensorflow进行音乐类型的分类
2020/08/14 Python
英国假睫毛购买网站:FalseEyelashes.co.uk
2018/05/23 全球购物
澳洲健康食品网上商店:Aussie Health Products
2018/06/15 全球购物
瑞典最大的儿童用品网上商店:pinkorblue.se
2021/03/09 全球购物
如何在发生故障的节点上重新安装 SQL Server
2013/03/14 面试题
勿忘国耻9.18演讲稿(经典篇)
2014/09/14 职场文书
十一国庆节“向国旗敬礼”主题班会活动方案
2014/09/27 职场文书
2015年校长新年寄语
2014/12/08 职场文书
检讨书怎么写
2015/01/23 职场文书
财务部岗位职责范本
2015/04/14 职场文书
JavaScript实现简单的音乐播放器
2022/08/14 Javascript