日期: 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. JMQ

    [京东技术]京东的MQ经历了JQ->AMQ->JMQ的发展,其中JQ的基于关系数据库,严格意义上讲称不上消息中间件,JMQ的存储是JFS和HBase,AMQ即ActiveMQ,本文说说JM ...

  2. Java不走弯路教程(前言)

    本教程的程序基于Windows开发,所以你需要有一台安装Windows操作系统的电脑. 前言本教程将带你完成Java的初学和WEB框架的开发,学完本教程,你将完成对Java的入门并且对下一步不再迷茫. ...

  3. Angular5 路由传参的3种方法

    一共3种方法. 1.问号后面带的参数,获取参数的方式:ActivatedRoute.queryParams[id] 例如:/product?id=1&name=iphone还可以是: [rou ...

  4. MeshCollider双面化脚本

    由于MeshCollider组件可以挂载多个,所以不需要Mesh重新合并了. 除了反转法线还需要反转所有三角面的顺序 脚本如下: using System.Collections; using Sys ...

  5. ACM Bee

    In Africa there is a very special species of bee. Every year, the female bees of such species give b ...

  6. Bootstrap3 表单-被支持的控件:文本域

    支持多行文本的表单控件.可根据需要改变 rows 属性. <textarea class="form-control" rows="3"></ ...

  7. Android简易实战教程--第四十九话《满屏拖动的控件》

    今天做个有意思的效果吧,控件的拖拽,简单实用,逻辑清晰点3分钟看完. 说的很高大上,其实就是拖动Button按钮跟着鼠标位置满手机屏幕跑罢了. 直接上简单的代码吧: public class Main ...

  8. 20160211.CCPP体系详解(0021天)

    程序片段(01):01.指针数组.c+02.动态数组.c 内容概要:指针数组 ///01.指针数组.c #include <stdio.h> #include <stdlib.h&g ...

  9. ROS(indigo) 用于机器人控制的图形化编程工具--code_it robot_blockly

    0 简介: 编程语言有汇编,高级语言,解释语言等,现在图形化编程也越来越流行.图形化编程简单易学.8年前,微软推出了VPL用于机器人程序设计,如Python和JavaScript都可以用图形化框图实现 ...

  10. [ExtJS5学习笔记]第三十五节 sencha extjs 5 组件查询方法总结

    一个UI前台组件肯定会比较多,我们通常习惯性的使用ID来获取需要操作的组件,但是这种方法是extjs推荐的么?有没有extjs推荐使用的获取组件的方法呢? 目录 目录 extjs的查询组件的API 查 ...