图片/图形

jQuery+CSS3鼠标滑过3D卡片翻转特效

阿里云


这是一款效果非常炫酷的 jQuery 和 CSS3 鼠标滑过 3D 卡片翻转特效。该卡片翻转特效使用 modernizr.js 来检测浏览器,当发现浏览器不支持 CSS3 翻转属性时,会将效果回退为简单的滑动显示效果。

制作方法

属性要引入 jQuery 和 modernizr.min.js 和 jquery.easing.min.js 文件。

也想出现在这里?联系我们
创客主机
  1. <script src="js/modernizr.min.js"></script>
  2. <script src="js/jquery.min.js"></script>
  3. <script src="js/jquery.easing.min.js"></script>

HTML 结构

该卡片翻转效果的 HTML 结构采用类似图片画廊的 HTML 结构:

  1. <div class="artGroup slide">
  2.   <div class="artwork"> <img src="1.jpg">
  3.     <div class="detail">
  4.       <h3>Title</h3>
  5.       <p>Details...</p>
  6.     </div>
  7.   </div>
  8. </div>

CSS 样式

为它添加一些必要的 CSS 样式:

  1. .artGroup {
  2.   display: block;
  3.   width: 200px;
  4.   height: 200px;
  5.   position: relative;
  6.   margin: 0 10px 10px 10px;
  7.   float: left;
  8. }
  9.  
  10. .artwork {
  11.   display: block;
  12.   width: 100%;
  13.   height: 100%;
  14. }
  15.  
  16. .artGroup img {
  17.   width: 100%;
  18.   height: 100%;
  19.   position: absolute;
  20.   display: block;
  21.   border: 1px solid #333;
  22. }
  23.  
  24. .artGroup .detail {
  25.   display: block;
  26.   background: #fff;
  27.   width: 100%;
  28.   height: 100%;
  29.   position: absolute;
  30. }
  31.  
  32. .artGroup .detail h3 {
  33.   text-align: center;
  34.   color: orange;
  35. }
  36.  
  37. .artGroup .detail p {
  38.   text-align: left;
  39.   padding: 0 0.25em;
  40. }

下面是使用 CSS3 来制作卡片翻转的效果:

  1. .artGroup.flip {
  2.   -webkit-perspective: 800px;
  3.   perspective: 800px;
  4. }
  5.  
  6. .artGroup.flip .artwork {
  7.   -webkit-transition: -webkit-transform 1s ease;
  8.   transition: transform 1s ease;
  9.   -webkit-transform-style: preserve-3d;
  10.   transform-style: preserve-3d;
  11. }
  12.  
  13. .artGroup.flip .detail,
  14. .artGroup.flip .theFlip {
  15.   -webkit-transform: rotateY(-180deg);
  16.   transform: rotateY(-180deg);
  17. }
  18.  
  19. .artGroup.flip img,
  20. .artGroup.flip .detail {
  21.   -webkit-backface-visibility: hidden;
  22.   backface-visibility: hidden;
  23. }

在旧浏览器中,使用下面的 CSS 来简单实现滑动效果。

  1. .artGroup.slide { overflow: hidden; }
  2. .artGroup.slide .detail { bottom: -364px; }

JAVASCRIPT

该卡片翻转特效使用 jQuery 来为相应的元素添加和删除相应的 class,完成卡片翻转的效果。

  1. $(function () {
  2. if ( $('html').hasClass('csstransforms3d') ) {
  3.   $('.artGroup').removeClass('slide').addClass('flip');
  4.   $('.artGroup.flip').on('mouseenter',
  5.     function () {
  6.       $(this).find('.artwork').addClass('theFlip');
  7.     });
  8.   $('.artGroup.flip').on('mouseleave',
  9.     function () {
  10.       $(this).find('.artwork').removeClass('theFlip');
  11.     });
  12. } else {
  13.   $('.artGroup').on('mouseenter',
  14.     function () {
  15.       $(this).find('.detail').stop().animate({bottom:0}, 500, 'easeOutCubic');
  16.     });
  17.   $('.artGroup').on('mouseleave',
  18.     function () {
  19.       $(this).find('.detail').stop().animate({bottom: ($(this).height() + -1) }, 500, 'easeOutCubic');
  20.     });
  21. }
  22. });

jQuery+CSS3 鼠标滑过 3D 卡片翻转特效

已有 355 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!