日期: 2013年9月23日

作者:铁锚

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

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

// 功能 :  在上方的按钮上滑动,可以切换各个page,点击下方的各个page,也可以切换收缩还是展开状态。

初始效果预览

<!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>

一个CSS+jQuery的放大缩小动画效果的更多相关文章

  1. 深入学习jQuery的三种常见动画效果

    × 目录 [1]显隐效果 [2]高度变化 [3]淡入淡出 前面的话 动画效果是jQuery吸引人的地方.通过jQuery的动画方法,能够轻松地为网页添加视觉效果,给用户一种全新的体验.jQuery动画 ...

  2. 一款很实用的jQuery鼠标悬浮有动画效果的响应式瀑布流插件

    一款很实用的jQuery鼠标悬浮有动画效果的响应式瀑布流插件 在线预览 下载地址 实例代码 <!doctype html> <html lang="zh"> ...

  3. 用C3中的animation和transform写的一个模仿加载的时动画效果

    用用C3中的animation和transform写的一个模仿加载的时动画效果! 不多说直接上代码; html标签部分 <div class="wrap"> <h ...

  4. jquery 最简单的动画效果

    <p style="border: 1px solid red"> 我会慢慢变大 </p> <a>dianji</a> <sc ...

  5. jQuery中的渐变动画效果

    jQuery中的渐变动画效果jQuery中的渐变动画效果

  6. 实现一个与内容合二为一的ActionBar动画效果

    实现一个与内容合二为一的ActionBar动画效果,让你的actionbar更生动.以下是效果图: 这样的效果的优点是让actionbar也成为了内容的一部分,实际应用的效果比图片展示的效果要好,除了 ...

  7. 简单css实现input提示交互动画效果

    通过基础CSS实现输入提示交互动画效果,并兼容各浏览器! 1.效果展示 2.css代码 h4 { margin: 30px 0; } input { margin:; font-size: 16px; ...

  8. Jquery绑定事件及动画效果

    Jquery绑定事件及动画效果 本文转载于:https://blog.csdn.net/Day_and_Night_2017/article/details/85799522 绑定事件 bind(ty ...

  9. 关于JQuery(最后一点动画效果*)

    1,$(':radio').val(['1','2','3']);//特殊写法,把值为1 2 3的都选中. 2,math.abs(len)取绝对值 3,按钮高亮显示,一般是配置两个按钮,一个普通的,一 ...

随机推荐

  1. ubuntu安装fat32和exfat文件系统支持

    vftp(fat32) apt install -y dosfstools exfat apt install -y exfat-fuse exfat-utils

  2. 判定程序员等级,HashMap就够了

    JDK1.8  HashMap源码分析 用到的符号: ^异运算:两个操作数相同,结果是;两个操作数不同,结果是1. &按位与:两个操作数都是1,结果才是1. 一.HashMap概述 在JDK1 ...

  3. 深入理解DirectByteBuffer

    介绍 最近在工作中使用到了DirectBuffer来进行临时数据的存放,由于使用的是堆外内存,省去了数据到内核的拷贝,因此效率比用ByteBuffer要高不少.之前看过许多介绍DirectBuffer ...

  4. CommonsChunkPlugin相关

    参考https://webpack.js.org/guides/caching/#deterministic-hashes var path = require("path"); ...

  5. 安卓框架——SlidingMenu使用技巧

    SlidingMenu的一些常用属性 原文转载http://blog.csdn.net/zwl5670/article/details/48274109 [java] view plain copy ...

  6. Android通过WebService实现图片的上传和下载(一)

    这篇文章将讲解Android如果通过访问WebService接口实现图片的上传和下载,当然这不但需要大家懂得Android还要懂得WebService技术,安卓属于客户端,而webservice则属于 ...

  7. 使用Android Studio向GitHub提交代码

    使用Android Studio向GitHub提交代码 在GitHub上创建一个仓库 填写仓库名称.描述.类型(公有.私有)等信息,点击创建 到此,成功创建了我们的仓库,并且初始化创建了README. ...

  8. 计算机网络中的TCP/IP模型

    Transmission Control Protocol/Internet Protocol的简写,中译名为传输控制协议/因特网互联协议,又名网络通讯协议,是Internet最基本的协议.Inter ...

  9. 值集&快速编码(Lookup_code)

    --值集 SELECT ffv.flex_value, ffv.description   FROM fnd_flex_values_vl ffv, fnd_flex_value_sets ffs   ...

  10. Findbugs异常总汇

    FindBugs是基于Bug Patterns概念,查找javabytecode(.class文件)中的潜在bug,主要检查bytecode中的bug patterns,如NullPoint空指针检查 ...