Skip to content

Commit 796a5e1

Browse files
committed
fix: #119 run animation when slide changes; (zh) 滚动页面时候执行动画
1 parent 3d8dee7 commit 796a5e1

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

back-end/h5-api/public/third-libs/swiper-animation.umd.min.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

back-end/h5-api/views/engine.ejs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--
22
* @Author: ly525
33
* @Date: 2019-12-04 20:24:04
4-
* @LastEditors: ly525
5-
* @LastEditTime: 2019-12-15 16:39:33
4+
* @LastEditors : ly525
5+
* @LastEditTime : 2020-01-24 21:03:29
66
* @FilePath: /luban-h5/back-end/h5-api/views/engine.ejs
77
* @Github: https://github.com/ly525/luban-h5
88
* @Description: 手机端预览模板
@@ -23,6 +23,7 @@
2323
<link rel="stylesheet" href="/third-libs/animate.min.css">
2424
<link rel="stylesheet" href="/third-libs/swiper.min.css">
2525
<script src="/third-libs/swiper.min.js"></script>
26+
<script src="/third-libs/swiper-animation.umd.min.js"></script>
2627
<script>window.__work = <%- JSON.stringify(work) %></script>
2728
<script src="/engine-assets/engine.umd.js"></script>
2829
<style>
@@ -256,6 +257,8 @@
256257
});
257258
</script>
258259
<script>
260+
const swiperAnimation = new SwiperAnimation();
261+
259262
var mySwiper = new Swiper('.swiper-container', {
260263
// Optional parameters
261264
direction: 'vertical',
@@ -273,6 +276,14 @@
273276
scrollbar: {
274277
el: '.swiper-scrollbar',
275278
},
279+
on: {
280+
init: function () {
281+
swiperAnimation.init(this).animate();
282+
},
283+
slideChange: function () {
284+
swiperAnimation.init(this).animate();
285+
}
286+
}
276287
});
277288
278289
function title(str) {

front-end/h5/src/components/core/models/element.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,17 @@ class Element {
9494
}
9595

9696
getAttrs () {
97-
return {
97+
const attrs = {
9898
'data-uuid': this.uuid
9999
}
100+
101+
if (this.animations.length > 0) {
102+
const animation = this.animations[0]
103+
attrs['data-swiper-animation'] = animation.type // "fadeIn"
104+
attrs['data-duration'] = `${animation.duration}s` // ".5s"
105+
attrs['data-delay'] = `${animation.delay}s` // "1s"
106+
}
107+
return attrs
100108
}
101109

102110
getPreviewData ({ position = 'static', isRem = false, mode = 'preview' } = {}) {

0 commit comments

Comments
 (0)