这是一款基于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. 头像上传ASP.NET MVC实现-可拖动大小实时预览

    这是一个ASP.NET MVC实现的类似于dz论坛的上传头像功能.可以拖动选择大小,支持多种尺寸生成. 效果界面 头像上传源码下载 项目中具体应用时,请根据需求做调整.欢迎交流~回复即可下载~源码下载 ...

  2. 从零开始学Hadoop系列之File System命令一

    1.Overview 文件系统(FS)shell包含多种能直接与HDFS(Hadoop Distributed File System)及Hadoop支持的其他文件系统,例如Local FS,HFTP ...

  3. Linux用户磁盘配额

    一:内核中支持QUOTA: [root@localhost /]# grep  CONFIG_QUOTA /boot/config-3.10.0-123.el7.x86_64 CONFIG_QUOTA ...

  4. Managing linux Shell Jobs

    Managing Shell Jobs   When moving jobs between the foreground and background, it may be useful to ha ...

  5. 详解ASP.NET MVC应用程序请求生命周期

    ------转载当一个ASP.NET MVC应用程序提出请求,为了响应请求,包含一些请求执行流程步骤! 在ASP.NET MVC应用程序Http request 和Http response 过程中, ...

  6. ASP.NET实现省市区三级联动(局部刷新)

    跟前一篇ASP.NET实现年月日三级联动(局部刷新)一样,没什么技术含量,直接上代码 <asp:ScriptManager ID="ScriptManager1" runat ...

  7. Windows7电脑上不去网,ipconfig查询时默认网关会出现0.0.0.0问题的解决

    用ipconfig查看网络配置,发现其他都正确,唯独默认网关上多了一条0.0.0.0的记录,.禁用网络连接再启用也不能恢复.网上找了一下有说改注册表的,打开注册表找到 HKEY_LOCAL_MACHI ...

  8. 经典shell面试题整理

    一.取出/etc/passwd文件中shell出现的次数 问题:下面是一个/etc/passwd文件的部分内容.题目要求取出shell并统计次数,shell是指后面的/bin/bash,/sbin/n ...

  9. C#操作MYSQL遇到0000-00-00日期报错的原因

    今天在做一个C#连接MYSQL数据库,并读取数据库的内容,遇到了0000-00-00日期转换报错:unable to convert MySQL date/time value to System.D ...

  10. javascript之闭包深入理解(二)

    在上一节中,详细理解了作用域链和垃圾回收机制,似乎这两点跟闭包关系不大,但是仔细想一想就会发现,其实不然.这一节将通过上一部分的说明详细理解闭包.请看代码: function createCompar ...