这是一款基于jQuery和CSS3的图片层叠展开特效,让鼠标滑过图片时即可触发这些特效。其中有一款就像扇子展开收拢一样,看起来效果都非常不错。当然本文主要还是来分析一下用jQuery实现这一效果的方法,具体效果可以在在线演示中查看。

你也可以在这里查看在线DEMO演示

说说实现的方法和代码吧,主要由HTML、CSS以及jQuery代码组成。

HTML代码:

<div id="page_wrap">
<!--Stack 1 -->
<div class="image_stack" style="margin-left:600px">
<img id="photo1" class="stackphotos" src="data:images/lanrenzhijia2.jpg" >
<img id="photo2" class="stackphotos" src="data:images/lanrenzhijia3.jpg" >
<img id="photo3" class="stackphotos" src="data:images/lanrenzhijia1.jpg" >
</div>
<!--Stack 2 -->
<div class="image_stack" style="margin-left:300px">
<img id="photo1" class="stackphotos" src="data:images/lanrenzhijia4.jpg" >
<img id="photo2" class="stackphotos" src="data:images/lanrenzhijia5.jpg" >
<img id="photo3" class="stackphotos" src="data:images/lanrenzhijia6.jpg" >
</div> <div class="single_photo">
<ul id="pics">
<li><a href="#pic1" title="Photo"><img src="data:images/lanrenzhijia3.jpg" alt="picture"></a></li>
</ul>
</div>
</div>

把要用到的小图片列出来,HTML结构非常简单。

接下来是CSS,相对复杂一点,因为有用到CSS3相关的一些特性。

CSS代码:

.image_stack img { /* css style for photo stack */
border: none;
text-decoration: none;
position: absolute;
margin-left:0px;
width: 158px;
height: 158px;
}
.image_stack { /* css style for photo stack */
width: 400px;
position: absolute;
margin:60px 10px 10px;
}
.image_stack img { /* css style for photo stack */
position: absolute;
border: 4px solid #FFF;
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
z-index:;
/* Firefox */
-moz-transition: all 0.2s ease;
/* WebKit */
-webkit-transition: all 0.2s ease;
/* Opera */
-o-transition: all 0.2s ease;
/* Standard */
transition: all 0.2s ease;
}
.image_stack #photo1 { /* position of last photo in the stack */
top: 8px;
left: 108px;
}
.image_stack #photo2 {/* position of middle photo in the stack */
top: 6px;
left: 104px;
}
.image_stack #photo3 {/* position of first photo at the top in the stack */
top: 4px;
left: 100px;
right: 100px;
}
.image_stack .rotate1 {/* rotate last image 15 degrees to the right */
-webkit-transform: rotate(15deg); /* safari and chrome */
-moz-transform: rotate(15deg);/*firefox browsers */
transform: rotate(15deg);/*other */
-ms-transform:rotate(15deg); /* Internet Explorer 9 */
-o-transform:rotate(15deg); /* Opera */
}
.image_stack .rotate2 {/* css not used*/
-webkit-transform: rotate(0deg); /* safari and chrome */
-moz-transform: rotate(0deg);/*firefox browsers */
transform: rotate(0deg);/*other */
-ms-transform:rotate(0deg); /* Internet Explorer 9 */
-o-transform:rotate(0deg); /* Opera */
}
.image_stack .rotate3 {/*rotate first image 15 degrees to the left*/
-webkit-transform: rotate(-15deg); /* safari and chrome */
-moz-transform: rotate(-15deg); /*firefox browsers */
transform: rotate(-15deg);/*other */
-ms-transform:rotate(-15deg); /* Internet Explorer 9 */
-o-transform:rotate(-15deg); /* Opera */
cursor: pointer;
}

看出来了吧,主要是rotate实现图片翻转折叠的效果,另外指定了0.2s的ease动画。

jQuery代码:

$(document).ready(function() {
$(".image_stack").delegate('img', 'mouseenter', function() {//when user hover mouse on image with div id=stackphotos
if ($(this).hasClass('stackphotos')) {//
// the class stackphotos is not really defined in css , it is only assigned to each images in the photo stack to trigger the mouseover effect on these photos only var $parent = $(this).parent();
$parent.find('img#photo1').addClass('rotate1');//add class rotate1,rotate2,rotate3 to each image so that it rotates to the correct degree in the correct direction ( 15 degrees one to the left , one to the right ! )
$parent.find('img#photo2').addClass('rotate2');
$parent.find('img#photo3').addClass('rotate3');
$parent.find('img#photo1').css("left","150px"); // reposition the first and last image
$parent.find('img#photo3').css("left","50px"); }
})
.delegate('img', 'mouseleave', function() {// when user removes cursor from the image stack
$('img#photo1').removeClass('rotate1');// remove the css class that was previously added to make it to its original position
$('img#photo2').removeClass('rotate2');
$('img#photo3').removeClass('rotate3');
$('img#photo1').css("left","");// remove the css property 'left' value from the dom
$('img#photo3').css("left",""); });;
});

其实jQuery也没什么事情,主要是动态为图片增加和删除类,用addClass和removeClass实现,这样鼠标滑过图片就可以翻转,鼠标离开图片又能够恢复,很不错吧。你也可以下载源代码研究。源码下载>>

jQuery/CSS3实现图片层叠展开特效的更多相关文章

  1. jQuery+CSS3实现404背景动画特效

    效果:http://hovertree.com/texiao/jquery/74/ 源码下载:http://hovertree.com/h/bjaf/ko0gcgw5.htm 效果图如下: 代码如下: ...

  2. 黄聪:手机移动端建站Jquery+CSS3+HTML5触屏滑动特效插件、实现触屏焦点图、图片轮展图

    前言 TouchSlide 可以说是 SuperSlide 手机简化版,不同的地方在于:1.TouchSlide是纯javascript开发的,不依赖任何js库,鉴于此,TouchSlide调用方法和 ...

  3. js实现左右点击图片层叠滚动特效

    需要加载js有 <script type="text/javascript" src="js/jquery-1.7.2.min.js"></s ...

  4. 20+功能强大的jQuery/CSS3图片特效插件

    以下是分享的20几个不错的图片特效插件,基于jQuery和CSS3. 1.jQuery图片下滑切换播放效果 这是一款基于jQuery的焦点图插件,这款焦点图的特点是有向下滑动的动画效果,滑到底部时,有 ...

  5. jQuery css3鼠标悬停图片显示遮罩层动画特效

    jQuery css3鼠标悬停图片显示遮罩层动画特效 效果体验:http://hovertree.com/texiao/jquery/39/ 效果图: 源码下载:http://hovertree.co ...

  6. 40免费的 jQuery & CSS3 图片热点特效

    jQuery CSS3 形象悬停效果可能是一个优秀的网站项目中添加的效果.这个特殊的收集是大约50个 jQuery CSS3 形象徘徊影响最近出版的.这些图像悬停效果可以作为一个有效的和创造性的方式添 ...

  7. Image Wall - jQuery & CSS3 图片墙效果

    今天我们要为您展示如何基于 jQuery 和 CSS3 创建一个整洁的图片墙效果.我们的想法是在页面上洒上一些大小不同的缩略图,并在当我们点击图片时候显示丝带,会显示一些描述,再次点击缩略图时,丝带将 ...

  8. 15款效果很酷的最新jQuery/CSS3特效

    很久没来博客园发表文章了,今天就分享15款效果很酷的最新jQuery/CSS3特效,废话不说,一起来看看吧. 1.3D图片上下翻牌切换 一款基于jQuery+CSS3实现的3D图片上下翻牌切换效果,支 ...

  9. 基于HTML5+CSS3的图片旋转、无限滚动、文字跳动特效

    本文分享几种基于HTML5+CSS3实现的一些动画特效:图片旋转.无限滚动.文字跳动;实现起来均比较容易,动手来试试! 一.图片旋转 效果图如下: 这个效果实现起来其实并不困难.代码清单如下: < ...

随机推荐

  1. JavaScript高级编程II

         原文地址: http://www.onlamp.com/pub/a/onlamp/2007/08/23/advanced-javascript-ii.html?page=1 在前面的文章中, ...

  2. 开发中可能会用到的几个 jQuery 小提示和技巧 (转)

    转自:http://www.cnblogs.com/lhb25/p/useful-jquery-tips-and-tricks.html 今天,我们将分享一些很有用的技巧和窍门给 jQuery 开发人 ...

  3. Java基础知识强化93:算一下你来到这个世界多少天的案例

    1. 分析: (1)键盘录入你的出生年月日 (2)把该字符串转换为一个日期 (3)通过该日期得到一个毫秒值 (4)获取当前时间的毫秒值 (5)用(4)-(3)得到一个毫秒值 (6)把E的毫秒值转换为天 ...

  4. Java基础知识强化31:String类之String的面试题

    1.先看一个图: 2.String面试题: (1)题1: package cn.itcast_02; /* * 看程序写结果 */ public class StringDemo3 { public ...

  5. MySQL(11):存储引擎

    1.存储引擎是什么?       MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择 ...

  6. 比较好的总结runtime

    http://www.cocoachina.com/ios/20160128/15154.html

  7. 6、第六课,js jquery20150928

    1.声明事件,给事件添加动作 function MyClick() { alert("这是我的第一个js") } 2.js特点 A.js区分大小写 B.弱类型变量,定义一个变量 v ...

  8. ASP.NET实现年月日三级联动(局部刷新)

    直接上代码,不多说别的了 <asp:ScriptManager ID="ScriptManager1" runat="server"> </a ...

  9. linux性能分析命令top

    发布时间: 2013-12-14浏览次数:154分类: 服务器 top是linux最常用的性能分析工具了,它是个交互式工具,提供系统的整体性能,如正在执行的进程信息包括进程ID,内存占用率,CPU占用 ...

  10. SQL Server 2008将数据导出为脚本

    之前我们要将一个表中的数据导出为脚本,那么只有在网上找一个导出数据的Script,然后运行就可以导出数据脚本了.现在在SQL Server 2008的Management Studio中增加了一个新特 ...