图片/图形

全屏对称分割卡片式轮播图jQuery插件

阿里云


这是一款 jQuery 全屏对称分割卡片式轮播图插件。该轮播图插件使用 jquery 和 TweenMax.js 来制作。在布局上,将图片和内容分为左右两块区域,轮播图切换时,带有一些视觉差效果。

使用方法

在页面中引入 jquery.min.js、TweenMax.min.js 文件。

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

HTML 结构

轮播图的 HTML 结构如下。

  1. <div class="slide active">
  2.   <div class="card">
  3.     <div class="card-img" id="img01"></div>
  4.       <div class="card-content">
  5.         <p class="card-theme">According to The Quote Verifier: Who Said What, Where, And When (2006)</p>
  6.         <h2 class="card-header">"If you can't stand the heat, get out of the kitchen."</h2>
  7.         <p class="card-para">by Eugene Purcell</p>
  8.         <a href="" class="card-link">Read</a>
  9.       </div>
  10.   </div>
  11. </div>
  12.  
  13. <div class="slide">
  14.   <div class="card">
  15.     <div class="card-img" id="img02"></div>
  16.       <div class="card-content">
  17.         <p class="card-theme">As quoted in Curiosities in proverbs, (1916) pg. 130</p>
  18.         <h2 class="card-header">"Never leave that till tomorrow which you can do today."</h2>
  19.         <p class="card-para">by Benjamin Franklin</p>
  20.         <a href="" class="card-link">Read</a>
  21.       </div>
  22.   </div>
  23. </div>
  24.  
  25. <div class="slide">
  26.   <div class="card">
  27.     <div class="card-img" id="img03"></div>
  28.       <div class="card-content">
  29.         <p class="card-theme">As quoted in How to Write a Book Proposal, (2011) pg. 19</p>
  30.         <h2 class="card-header">"Nothing is particularly hard if you divide it into small jobs."</h2>
  31.         <p class="card-para">by Henry Ford</p>
  32.         <a href="" class="card-link">Read</a>
  33.       </div>
  34.   </div>
  35. </div>
  36. <div class="prevnext">
  37.   <button class="pn-btn" id="prev"></button>
  38.   <button class="pn-btn" id="next"></button>
  39. </div>

CSS 样式

为轮播图添加下面的 CSS 样式。

  1. .slide{
  2.   display: flex;
  3.   justify-content: center;
  4.   align-items: center;
  5.   flex-wrap: wrap;
  6.   flex-direction: column;
  7.   width: 100%;
  8.   height: 100%;
  9. }
  10.  
  11. .card{
  12.   width: 100%;
  13.   height: 100vh;
  14.   display: flex;
  15.   background: #fff;
  16. }
  17.  
  18. .card-img{
  19.   background-position: center;
  20.   width: 50%;
  21.   height: 100%;
  22.   background-size: cover;
  23.   background-repeat: no-repeat;
  24. }
  25.  
  26. .card-content{
  27.   padding: 10% 5%;
  28.   box-sizing: border-box;
  29.   width: 50%;
  30.   background: #0A0A0A;
  31. }
  32.  
  33. .card-theme{
  34.   font-weight: 900;
  35.   font-size: 1.7vmin;
  36.   text-transform: uppercase;
  37.   font-family: Poppins;
  38.   letter-spacing: 10px;
  39.   color: grey;
  40. }
  41.  
  42. .card-header{
  43.   font-weight: 700;
  44.   font-size: 54px;
  45.   text-transform: capitalize;
  46.   line-height: 1;
  47.   margin: 3vmin 0 3.5vmin;
  48.   color: #fff;
  49.   font-family: Poppins;
  50. }
  51.  
  52. .card-para{
  53.   font-size: 1.6vmin;
  54.   line-height: 1.8;
  55.   font-weight: 300;
  56.   margin-bottom: 2.5vmin;
  57.   color: #fff;
  58.   font-family: Poppins;
  59. }
  60.  
  61. .card-link{
  62.   color: #fff;
  63.   font-family: Poppins;
  64.   font-size: 1.8vmin;
  65.   display: block;
  66.   cursor: pointer;
  67.   text-decoration: none;
  68.   opacity: 0.7;
  69.   transition: opacity 0.3s ease;
  70. }
  71.  
  72. .card-link:after{
  73.   content: " →";
  74. }
  75. /*背景图片*/
  76. #img01{
  77.   background-image: url("img01.jpg");
  78. }
  79.  
  80. #img02{
  81.   background-image: url("img02.jpg");
  82. }
  83.  
  84. #img03{
  85.   background-image: url("img03.jpg");
  86. }
  87. /*前后导航按钮样式*/
  88. .prevnext{
  89.   position: absolute;
  90.   width: 4vmin;
  91.   height: 8vmin;
  92.   right: 2%;
  93.   bottom: 0;
  94.   top: 80%;
  95.   color: #fff;
  96.   margin: auto 0;
  97. }
  98.  
  99. .pn-btn{
  100.   color: #fff;
  101.   width: 100%;
  102.   height: 50%;
  103.   border: 0;
  104.   background-color: transparent;
  105.   font-size: 20px;
  106. }
  107.  
  108. #prev, #next{
  109.   position: relative;
  110.   cursor: pointer;
  111. }
  112.  
  113. #prev:focus, #next:focus{
  114.   outline: none;
  115. }
  116.  
  117. #prev:hover:after, #next:hover:after{
  118.   opacity: 1;
  119. }
  120.  
  121. #prev:after, #next:after{
  122.   position: absolute;
  123.   width: 100%;
  124.   height: 100%;
  125.   left: 0;
  126.   top: 0;
  127.   right: 0;
  128.   bottom: 0;
  129.   opacity: 0.6;
  130.   transition: opacity 0.3s ease;
  131. }
  132.  
  133. #prev:after{
  134.   content: "↑";
  135. }
  136.  
  137. #next:after{
  138.   content: "↓";
  139. }

初始化插件

在页面 DOM 元素加载完毕之后,通过下面的方法来初始化该插件。

  1. var $activeSlide = $('.active'),
  2.     $homeSlide = $(".slide"),
  3.     $slideNavPrev = $("#prev"),
  4.     $slideNavNext = $("#next");
  5.  
  6. function init() {
  7.   TweenMax.set($homeSlide.not($activeSlide), {autoAlpha: 0});
  8.   TweenMax.set($slideNavPrev, {autoAlpha: 0.2});
  9. }
  10.  
  11. init();
  12.  
  13. function goToNextSlide(slideOut, slideIn, slideInAll) {
  14.   var t1 = new TimelineLite(),
  15.   slideOutContent = slideOut.find('.card-content'),
  16.   slideInContent = slideIn.find('.card-content'),
  17.   slideOutImg = slideOut.find('.card-img'),
  18.   slideInImg = slideIn.find('.card-img'),
  19.   index = slideIn.index(),
  20.   size = $homeSlide.length;
  21.   console.log(index);
  22.  
  23.   if(slideIn.length !== 0) {
  24.   t1
  25.   .set(slideIn, {autoAlpha: 1, className: '+=active'})
  26.   .set(slideOut, {className: '-=active'})
  27.   .to(slideOutContent, 0.65, {y: "+=40px", ease: Power3.easeInOut}, 0)
  28.   .to(slideOutImg, 0.65, {backgroundPosition :'bottom', ease: Power3.easeInOut}, 0)
  29.   .to(slideInAll, 1, {y: "-=100%", ease: Power3.easeInOut}, 0)
  30.   .fromTo(slideInContent, 0.65, {y: '-=40px'}, {y : 0, ease: Power3.easeInOut}, "-=0.7")
  31.   .fromTo(slideInImg, 0.65, {backgroundPosition: 'top'}, {backgroundPosition: 'bottom', ease: Power3.easeInOut}, '-=0.7')
  32.   }
  33.  
  34.   TweenMax.set($slideNavPrev, {autoAlpha: 1});
  35.  
  36.   if(index === size - 1){
  37.         TweenMax.to($slideNavNext, 0.3, {autoAlpha: 0.2, ease:Linear.easeNone});
  38.   }
  39. };
  40.  
  41. $slideNavNext.click(function(e) {
  42.   e.preventDefault();
  43.  
  44.   var slideOut = $('.slide.active'),
  45.   slideIn = $('.slide.active').next('.slide'),
  46.   slideInAll = $('.slide');
  47.  
  48.   goToNextSlide(slideOut, slideIn, slideInAll);
  49.  
  50. });
  51.  
  52. function goToPrevSlide(slideOut, slideIn, slideInAll) {
  53.   var t1 = new TimelineLite(),
  54.   slideOutContent = slideOut.find('.card-content'),
  55.   slideInContent = slideIn.find('.card-content'),
  56.   slideOutImg = slideOut.find('.card-img'),
  57.   slideInImg = slideIn.find('.card-img'),
  58.   index = slideIn.index(),
  59.   size = $homeSlide.length;
  60.  
  61.   if(slideIn.length !== 0) {
  62.   t1
  63.   .set(slideIn, {autoAlpha: 1, className: '+=active'})
  64.   .set(slideOut, {className: '-=active'})
  65.   .to(slideOutContent, 0.65, {y: "-=40px", ease: Power3.easeInOut}, 0)
  66.   .to(slideOutImg, 0.65, {backgroundPosition :'top', ease: Power3.easeInOut}, 0)
  67.   .to(slideInAll, 1, {y: "+=100%", ease: Power3.easeInOut}, 0)
  68.   .fromTo(slideInContent, 0.65, {y: '+=40px'}, {y : 0, ease: Power3.easeInOut}, "-=0.7")
  69.   .fromTo(slideInImg, 0.65, {backgroundPosition: 'bottom'}, {backgroundPosition: 'top', ease: Power3.easeInOut}, '-=0.7')
  70.   }
  71.  
  72.   TweenMax.set($slideNavPrev, {autoAlpha: 1});
  73.  
  74.   if(index === 0){
  75.         TweenMax.to($slideNavPrev, 0.3, {autoAlpha: 0.2, ease:Linear.easeNone});
  76.   }
  77. };
  78.  
  79. $slideNavPrev.click(function(e) {
  80.   e.preventDefault();
  81.  
  82.   var slideOut = $('.slide.active'),
  83.   slideIn = $('.slide.active').prev('.slide'),
  84.   slideInAll = $('.slide');
  85.  
  86.   goToPrevSlide(slideOut, slideIn, slideInAll);
  87.  
  88. });

Github 网址:https://github.com/r4nd3l/jQueryContentSlider

全屏对称分割卡片式轮播图 jQuery 插件

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

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

发表回复

热销模板

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

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