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

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

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

使用方法
在页面中引入jquery.min.js、TweenMax.min.js文件。

1
2
<script  src="js/jquery.min.js"></script>        
<script  src="js/TweenMax.min.js"></script>

HTML结构
轮播图的HTML结构如下。

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
.slide{
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  flex-direction: column;
  width: 100%;
  height: 100%;
}
 
.card{
  width: 100%;
  height: 100vh;
  display: flex;
  background: #fff;
}
 
.card-img{
  background-position: center;
  width: 50%;
  height: 100%;
  background-size: cover;
  background-repeat: no-repeat;
}
 
.card-content{
  padding: 10% 5%;
  box-sizing: border-box;
  width: 50%;
  background: #0A0A0A;
}
 
.card-theme{
  font-weight: 900;
  font-size: 1.7vmin;
  text-transform: uppercase;
  font-family: Poppins;
  letter-spacing: 10px;
  color: grey;
}
 
.card-header{
  font-weight: 700;
  font-size: 54px;
  text-transform: capitalize;
  line-height: 1;
  margin: 3vmin 0 3.5vmin;
  color: #fff;
 font-family: Poppins;
}
 
.card-para{
  font-size: 1.6vmin;
  line-height: 1.8;
  font-weight: 300;
  margin-bottom: 2.5vmin;
  color: #fff;
 font-family: Poppins;
}
 
.card-link{
  color: #fff;
 font-family: Poppins;
  font-size: 1.8vmin;
  display: block;
  cursor: pointer;
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.3s ease;
}
 
.card-link:after{
  content: " →";
}
/*背景图片*/
#img01{
 background-image: url("img01.jpg");
}
 
#img02{
 background-image: url("img02.jpg");
}
 
#img03{
 background-image: url("img03.jpg");
}
/*前后导航按钮样式*/
.prevnext{
  position: absolute;
  width: 4vmin;
  height: 8vmin;
  right: 2%;
  bottom: 0;
  top: 80%;
  color: #fff;
 margin: auto 0;
}
 
.pn-btn{
  color: #fff;
 width: 100%;
  height: 50%;
  border: 0;
  background-color: transparent;
  font-size: 20px;
}
 
#prev, #next{
 position: relative;
  cursor: pointer;
}
 
#prev:focus, #next:focus{
 outline: none;
}
 
#prev:hover:after, #next:hover:after{
 opacity: 1;
}
 
#prev:after, #next:after{
 position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  opacity: 0.6;
  transition: opacity 0.3s ease;
}
 
#prev:after{
 content: "↑";
}
 
#next:after{
 content: "↓";
}
 初始化插件
在页面DOM元素加载完毕之后,通过下面的方法来初始化该插件。

var $activeSlide = $('.active'),
    $homeSlide = $(".slide"),
    $slideNavPrev = $("#prev"),
    $slideNavNext = $("#next");
 
function init() {
  TweenMax.set($homeSlide.not($activeSlide), {autoAlpha: 0});
  TweenMax.set($slideNavPrev, {autoAlpha: 0.2});
}
 
init();
 
function goToNextSlide(slideOut, slideIn, slideInAll) {
  var t1 = new TimelineLite(),
  slideOutContent = slideOut.find('.card-content'),
  slideInContent = slideIn.find('.card-content'),
  slideOutImg = slideOut.find('.card-img'),
  slideInImg = slideIn.find('.card-img'),
  index = slideIn.index(),
  size = $homeSlide.length;
  console.log(index);
 
  if(slideIn.length !== 0) {
  t1
  .set(slideIn, {autoAlpha: 1, className: '+=active'})
  .set(slideOut, {className: '-=active'})
  .to(slideOutContent, 0.65, {y: "+=40px", ease: Power3.easeInOut}, 0)
  .to(slideOutImg, 0.65, {backgroundPosition :'bottom', ease: Power3.easeInOut}, 0)
  .to(slideInAll, 1, {y: "-=100%", ease: Power3.easeInOut}, 0)
  .fromTo(slideInContent, 0.65, {y: '-=40px'}, {y : 0, ease: Power3.easeInOut}, "-=0.7")
  .fromTo(slideInImg, 0.65, {backgroundPosition: 'top'}, {backgroundPosition: 'bottom', ease: Power3.easeInOut}, '-=0.7')
  }
 
  TweenMax.set($slideNavPrev, {autoAlpha: 1});
 
  if(index === size - 1){
        TweenMax.to($slideNavNext, 0.3, {autoAlpha: 0.2, ease:Linear.easeNone});
  }
};
 
$slideNavNext.click(function(e) {
  e.preventDefault();
 
  var slideOut = $('.slide.active'),
  slideIn = $('.slide.active').next('.slide'),
  slideInAll = $('.slide');
 
  goToNextSlide(slideOut, slideIn, slideInAll);
 
});
 
function goToPrevSlide(slideOut, slideIn, slideInAll) {
  var t1 = new TimelineLite(),
  slideOutContent = slideOut.find('.card-content'),
  slideInContent = slideIn.find('.card-content'),
  slideOutImg = slideOut.find('.card-img'),
  slideInImg = slideIn.find('.card-img'),
  index = slideIn.index(),
  size = $homeSlide.length;
 
  if(slideIn.length !== 0) {
  t1
  .set(slideIn, {autoAlpha: 1, className: '+=active'})
  .set(slideOut, {className: '-=active'})
  .to(slideOutContent, 0.65, {y: "-=40px", ease: Power3.easeInOut}, 0)
  .to(slideOutImg, 0.65, {backgroundPosition :'top', ease: Power3.easeInOut}, 0)
  .to(slideInAll, 1, {y: "+=100%", ease: Power3.easeInOut}, 0)
  .fromTo(slideInContent, 0.65, {y: '+=40px'}, {y : 0, ease: Power3.easeInOut}, "-=0.7")
  .fromTo(slideInImg, 0.65, {backgroundPosition: 'bottom'}, {backgroundPosition: 'top', ease: Power3.easeInOut}, '-=0.7')
  }
 
  TweenMax.set($slideNavPrev, {autoAlpha: 1});
 
  if(index === 0){
        TweenMax.to($slideNavPrev, 0.3, {autoAlpha: 0.2, ease:Linear.easeNone});
  }
};
 
$slideNavPrev.click(function(e) {
  e.preventDefault();
 
  var slideOut = $('.slide.active'),
  slideIn = $('.slide.active').prev('.slide'),
  slideInAll = $('.slide');
 
  goToPrevSlide(slideOut, slideIn, slideInAll);
 
});
当前内容只有登录了才能查看,如果您已经注册,请登录
1

发表评论