一个CSS+jQuery的放大缩小动画效果
日期: 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的放大缩小动画效果的更多相关文章
- 深入学习jQuery的三种常见动画效果
× 目录 [1]显隐效果 [2]高度变化 [3]淡入淡出 前面的话 动画效果是jQuery吸引人的地方.通过jQuery的动画方法,能够轻松地为网页添加视觉效果,给用户一种全新的体验.jQuery动画 ...
- 一款很实用的jQuery鼠标悬浮有动画效果的响应式瀑布流插件
一款很实用的jQuery鼠标悬浮有动画效果的响应式瀑布流插件 在线预览 下载地址 实例代码 <!doctype html> <html lang="zh"> ...
- 用C3中的animation和transform写的一个模仿加载的时动画效果
用用C3中的animation和transform写的一个模仿加载的时动画效果! 不多说直接上代码; html标签部分 <div class="wrap"> <h ...
- jquery 最简单的动画效果
<p style="border: 1px solid red"> 我会慢慢变大 </p> <a>dianji</a> <sc ...
- jQuery中的渐变动画效果
jQuery中的渐变动画效果jQuery中的渐变动画效果
- 实现一个与内容合二为一的ActionBar动画效果
实现一个与内容合二为一的ActionBar动画效果,让你的actionbar更生动.以下是效果图: 这样的效果的优点是让actionbar也成为了内容的一部分,实际应用的效果比图片展示的效果要好,除了 ...
- 简单css实现input提示交互动画效果
通过基础CSS实现输入提示交互动画效果,并兼容各浏览器! 1.效果展示 2.css代码 h4 { margin: 30px 0; } input { margin:; font-size: 16px; ...
- Jquery绑定事件及动画效果
Jquery绑定事件及动画效果 本文转载于:https://blog.csdn.net/Day_and_Night_2017/article/details/85799522 绑定事件 bind(ty ...
- 关于JQuery(最后一点动画效果*)
1,$(':radio').val(['1','2','3']);//特殊写法,把值为1 2 3的都选中. 2,math.abs(len)取绝对值 3,按钮高亮显示,一般是配置两个按钮,一个普通的,一 ...
随机推荐
- zookeeper工作机制
Zookeeper Zookeeper概念简介: Zookeeper是为用户的分布式应用程序提供协调服务的 zookeeper是为别的分布式程序服务的 Zookeeper本身就是一个分布式程序(只要有 ...
- Node.js NPM 使用介绍
NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从NPM服务器下载并 ...
- Docker常见仓库WordPress
WordPress 基本信息 WordPress 是开源的 Blog 和内容管理系统框架,它基于 PhP 和 MySQL. 该仓库提供了 WordPress 4.0 版本的镜像. 使用方法 启动容器需 ...
- Bootstrap3 排版-内联文本元素
标记文本 突出显示的文本由于其相关性在另一个上下文中,使用<mark>标记. You can use the mark tag to highlight text. You can use ...
- leetcode 之 Single Number II
问题来源:Single Number II 问题描述:给定一个整数数组,除了一个整数出现一次之外,其余的每一个整数均出现三次,请找出这个出现一次的整数. 大家可能很熟悉另一个题目(Single Num ...
- android MultiDex multidex原理原理下遇见的N个深坑(二)
android MultiDex 原理下遇见的N个深坑(二) 这是在一个论坛看到的问题,其实你不知道MultiDex到底有多坑. 不了解的可以先看上篇文章:android MultiDex multi ...
- Objective-C基础之简析深浅copy
一.从面向对象到Objective-C概览copy 1.面向对象: In object-oriented programming, object copying is creating a copy ...
- Lua判断OS并添加cpath
Lua判断OS并添加cpath(金庆的专栏)Lua初始化时需要根据OS来设置package.cpath, 如果是Windows系统则添加 ?.dll, 否则添加 ?.so.不然加载错误后缀名的动态库会 ...
- Linux 高性能服务器编程——多进程编程
问题聚焦: 进程是Linux操作系统环境的基础. 本篇讨论以下几个内容,同时也是面试经常被问到的一些问题: 1 复制进程映像的fork系统调用和替换进程映像的exec系列系统调 ...
- Dynamics CRM2016 Web API之删除
相比之前的增改查,删除就显得简单的多了. 这里的request的type为delete,删除成功的status为204,404则是要删除的记录不存在 var id = 'BAD90A95-7FEA-E ...