幻灯片/轮播

jQuery和css3简单3D背景幻灯片插件

阿里云


这是一款降到实用的 jQuery 和 css3 3D 背景幻灯片插件。该幻灯片插件背景实用 css3 制作卷纸阴影 3d 效果,幻灯片采用淡入淡出的轮播方式,并带有圆点导航按钮和图片标题动画。

HTML 结构:

html 结构使用一个 section 作为 wrapper,在里面使用无序列表作为幻灯片。空的 div .shadow 是用于制作背景的 3d 阴影效果。空的无序列表.slider-controls 用于制作圆点导航按钮。

也想出现在这里?联系我们
创客主机
  1. <section class="slider-container">
  2.     <ul id="slider" class="slider-wrapper">
  3.         <li class="slide-current">
  4.             <img src="images/1.jpg" alt="Slider Imagen 1">
  5.             <div class="caption">
  6.                 <h3 class="caption-title">Diseño web</h3>
  7.                 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Debitis, ea.</p>
  8.             </div>
  9.         </li>
  10.  
  11.         <li>
  12.             <img src="images/2.jpg" alt="Slider Imagen 2">
  13.             <div class="caption">
  14.                 <h3 class="caption-title">Desarrollo web</h3>
  15.                 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Debitis, ea.</p>
  16.             </div>
  17.         </li>
  18.  
  19.         <li>
  20.             <img src="images/3.jpg" alt="Slider Imagen 3">
  21.             <div class="caption">
  22.                 <h3 class="caption-title">Javascript</h3>
  23.                 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Debitis, ea.</p>
  24.             </div>
  25.         </li>
  26.  
  27.         <li>
  28.             <img src="images/4.jpg" alt="Slider Imagen 4">
  29.             <div class="caption">
  30.                 <h3 class="caption-title">Maquetacion</h3>
  31.                 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Debitis, ea.</p>
  32.             </div>
  33.         </li>
  34.     </ul>
  35.  
  36.     <!-- Sombras -->
  37.     <div class="shadow"></div>
  38.  
  39.     <!-- Controles -->
  40.     <ul id="slider-controls" class="slider-controls"></ul>
  41. </section>

CSS 样式:

下面来给幻灯片添加一些样式。

  1. * {
  2.     margin: 0;
  3.     padding: 0;
  4.     -webkit-box-sizing: border-box;
  5.     -moz-box-sizing: border-box;
  6.     box-sizing: border-box;
  7. }
  8.  
  9. body {
  10.     background: #242c38;
  11.     font-family: 'Roboto', Arial, Tahoma, Sans-serif, Verdana, Helvetica;
  12.     font-size: 62.5%;
  13. }
  14.  
  15. a {
  16.     color: #00c5b9;
  17.     text-decoration: none;
  18. }
  19.  
  20. ul {
  21.     list-style-type: none;
  22. }
  23.  
  24. /*
  25. Encabezado del Slider
  26.  ----------------------------------------*/
  27. .slider-title {
  28.     text-align: center;
  29.     margin: 80px 0 40px;
  30.     font-size: 3.2em;
  31.     font-weight: 300;
  32.     color: #FFF;
  33. }
  34.  
  35. /**
  36.  * Contendor del Slider
  37.  ----------------------------------------*/
  38. .slider-container {
  39.     margin: 0 auto;
  40.     width: 800px;
  41. }
  42.  
  43. .slider-wrapper {
  44.     position: relative;
  45.     z-index: 90;
  46.     height: 360px;
  47.     width: 100%;
  48.     border: 5px solid #415066;
  49.     overflow: hidden;
  50. }
  51.  
  52. .slider-wrapper li {
  53.     display: none;
  54. }
  55.  
  56. li.slide-current {
  57.     display: block;
  58. }
  59.  
  60. .slider-wrapper li img {
  61.     position: absolute;
  62.     top: 0;
  63.     left: 0;
  64.     max-width: 100%;
  65.     height: auto;
  66. }

下面是图片标题和背景阴影的 CSS 样式,以及用于各种屏幕的媒体查询样式:

  1. /**
  2.  * Caption
  3.  ----------------------------------------*/
  4. .caption {
  5.     position: absolute;
  6.     bottom: 0;
  7.     left: 0;
  8.     width: 100%;
  9.     background: rgba(0,0,0,0.6);
  10.     padding: 12px;
  11.     -webkit-transform: translateY(100%);
  12.     -ms-transform: translateY(100%);
  13.     -o-transform: translateY(100%);
  14.     transform: translateY(100%);
  15.     -webkit-transition: all 0.3s ease;
  16.     -o-transition: all 0.3s ease;
  17.     transition: all 0.3s ease;
  18. }
  19. .caption-title {
  20.     color: #00c5b9;
  21.     font-weight: 700;
  22.     font-size: 1.6em;
  23.     margin-bottom: 10px;
  24. }
  25. .caption p {
  26.     color: #FFF;
  27.     font-size: 1.4em;
  28.     line-height: 1.3em;
  29. }
  30. .slider-wrapper li:hover .caption {
  31.     -webkit-transform: translateY(0);
  32.     -ms-transform: translateY(0);
  33.     -o-transform: translateY(0);
  34.     transform: translateY(0);
  35. }
  36. /**
  37.  * Sombras
  38.  ----------------------------------------*/
  39. .shadow {
  40.     width: 100%;
  41.     height: 15px;
  42.     position: relative;
  43. }
  44. .shadow:after, .shadow:before {
  45.     content: '';
  46.     width: 50%;
  47.     height: 100%;
  48.     background: #171c24;
  49.     position: absolute;
  50.     left: 10px;
  51.     top: -20px;
  52.     -webkit-transform: rotate(-4deg);
  53.     -ms-transform: rotate(-4deg);
  54.     -o-transform: rotate(-4deg);
  55.     transform: rotate(-4deg);
  56.     -webkit-box-shadow: 0 0 15px 8px #171c24;
  57.     -moz-box-shadow: 0 0 15px 8px #171c24;
  58.     box-shadow: 0 0 15px 8px #171c24;
  59. }
  60. .shadow:after {
  61.     left: auto;
  62.     right: 10px;
  63.     -webkit-transform: rotate(4deg);
  64.     -ms-transform: rotate(4deg);
  65.     -o-transform: rotate(4deg);
  66.     transform: rotate(4deg);
  67. }
  68. /**
  69.  * Controles del Slider
  70.  ----------------------------------------*/
  71. .slider-controls {
  72.     text-align: center;
  73.     margin-top: 15px;
  74. }
  75. .slider-controls li {
  76.     background: #415066;
  77.     -webkit-border-radius: 50%;
  78.     -moz-border-radius: 50%;
  79.     border-radius: 50%;
  80.     display: inline-block;
  81.     height: 12px;
  82.     width: 12px;
  83.     margin: 0 4px;
  84.     cursor: pointer;
  85. }
  86. .slider-controls li.active {
  87.     background: #00c5b9;
  88. }
  89. /**
  90.  * Autores
  91.  ----------------------------------------*/
  92. .authors {
  93.     margin-bottom: 15px;
  94.     margin-top: 25px;
  95.     color: #415066;
  96.     font-size: 1.4em;
  97.     text-align: center;
  98. }
  99. /**
  100.  * Responsive
  101.  ----------------------------------------*/
  102. @media only screen and (max-width: 825px) {
  103.     .slider-container {
  104.         width: 500px;
  105.     }
  106.     .slider-wrapper {
  107.         height: 260px;
  108.     }
  109. }
  110. @media only screen and (max-width: 535px) {
  111.     .slider-container {
  112.         padding: 5px;
  113.         width: 100%;
  114.     }
  115.     .slider-wrapper {
  116.         height: 200px;
  117.     }
  118.     .caption {
  119.         display: none;
  120.     }
  121. }
  122. @media only screen and (max-width: 410px) {
  123.     .slider-wrapper {
  124.         height: 160px;
  125.     }
  126. }

JAVASCRIPT 代码:

  1. $(function() {
  2.     var SliderModule = (function() {
  3.         var pb = {};
  4.         pb.el = $('#slider');
  5.         pb.items = {
  6.             panel: pb.el.find('li')
  7.         }
  8.         // Variables Necesarias
  9.         var SliderInterval,
  10.             currentSlider = 0,
  11.             nextSlider = 1,
  12.             lengthSlider = pb.items.panel.length;
  13.         // Initialize
  14.         pb.init = function(settings) {
  15.             this.settings = settings || {duration: 8000}
  16.             var output = '';
  17.             // Activamos nuestro slider
  18.             SliderInit();
  19.             for(var i = 0; i < lengthSlider; i++) {
  20.                 if (i == 0) {
  21.                     output += '<li class="active"></li>';
  22.                 } else {
  23.                     output += '<li></li>';
  24.                 }
  25.             }
  26.             // Controles del Slider
  27.             $('#slider-controls').html(output).on('click', 'li', function (e){
  28.                 var $this = $(this);
  29.                 if (currentSlider !== $this.index()) {
  30.                     changePanel($this.index());
  31.                 };
  32.             });
  33.         }
  34.         var SliderInit = function() {
  35.             SliderInterval = setInterval(pb.startSlider, pb.settings.duration);
  36.         }
  37.         pb.startSlider = function() {
  38.             var panels = pb.items.panel,
  39.                 controls = $('#slider-controls li');
  40.             if (nextSlider >= lengthSlider) {
  41.                 nextSlider = 0;
  42.                 currentSlider = lengthSlider-1;
  43.             }
  44.             // Efectos
  45.             controls.removeClass('active').eq(nextSlider).addClass('active');
  46.             panels.eq(currentSlider).fadeOut('slow');
  47.             panels.eq(nextSlider).fadeIn('slow');
  48.             // Actualizamos nuestros datos
  49.             currentSlider = nextSlider;
  50.             nextSlider += 1;
  51.         }
  52.         // Funcion para controles del slider
  53.         var changePanel = function(id) {
  54.             clearInterval(SliderInterval);
  55.             var panels = pb.items.panel,
  56.                 controls = $('#slider-controls li');
  57.             // Comprobamos el ID
  58.             if (id >= lengthSlider) {
  59.                 id = 0;
  60.             } else if (id < 0) {
  61.                 id = lengthSlider-1;
  62.             }
  63.             // Efectos
  64.             controls.removeClass('active').eq(id).addClass('active');
  65.             panels.eq(currentSlider).fadeOut('slow');
  66.             panels.eq(id).fadeIn('slow');
  67.             // Actualizamos nuestros datos
  68.             currentSlider = id;
  69.             nextSlider = id+1;
  70.  
  71.             // Reactivamos el slider
  72.             SliderInit();
  73.         }
  74.         return pb;
  75.     }());
  76.     SliderModule.init({duration: 6000});
  77. });

jQuery 和 css3 简单 3D 背景幻灯片插件

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

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

发表回复

热销模板

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

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