|
1 | 1 | <style lang="less"> |
| 2 | + .container { |
| 3 | + height: 640px; |
| 4 | + overflow: auto; |
| 5 | + } |
| 6 | +
|
| 7 | + .lazy-ref { |
| 8 | + } |
| 9 | +
|
| 10 | + img { |
| 11 | + width: 200px; |
| 12 | + height: 200px; |
| 13 | + } |
| 14 | +
|
| 15 | + .lazy-loading { |
| 16 | + &:before { |
| 17 | + content: ""; |
| 18 | + display: block; |
| 19 | + width: 40px; |
| 20 | + height: 40px; |
| 21 | + position: absolute; |
| 22 | + left: 50%; |
| 23 | + top: 50%; |
| 24 | + margin: -20px 0 0 -20px; |
| 25 | + background-color: #333; |
| 26 | + -webkit-animation: sk-rotateplane 1.2s infinite ease-in-out; |
| 27 | + animation: sk-rotateplane 1.2s infinite ease-in-out; |
| 28 | + } |
| 29 | + position: relative; |
| 30 | + width: 200px; |
| 31 | + height: 200px; |
| 32 | + } |
| 33 | +
|
| 34 | + @-webkit-keyframes sk-rotateplane { |
| 35 | + 0% { |
| 36 | + -webkit-transform: perspective(120px) |
| 37 | + } |
| 38 | + 50% { |
| 39 | + -webkit-transform: perspective(120px) rotateY(180deg) |
| 40 | + } |
| 41 | + 100% { |
| 42 | + -webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg) |
| 43 | + } |
| 44 | + } |
| 45 | +
|
| 46 | + @keyframes sk-rotateplane { |
| 47 | + 0% { |
| 48 | + transform: perspective(120px) rotateX(0deg) rotateY(0deg); |
| 49 | + -webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg) |
| 50 | + } |
| 51 | + 50% { |
| 52 | + transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg); |
| 53 | + -webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg) |
| 54 | + } |
| 55 | + 100% { |
| 56 | + transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg); |
| 57 | + -webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg); |
| 58 | + } |
| 59 | + } |
2 | 60 | </style> |
3 | 61 | <template> |
4 | 62 | <div> |
5 | | - <lazy-ref ref="lazyRef" class="lazy-ref" v-if="show"> |
6 | | - <div> |
7 | | - <img v-lazy="{ref:'lazyRef', src:img}"> |
8 | | - </div> |
9 | | - </lazy-ref> |
| 63 | + <div class="container"> |
| 64 | + <div class="lazy-loading"></div> |
| 65 | + <lazy-ref ref="lazyRef" class="lazy-ref" opts="{classTarget:'parent'}"> |
| 66 | + <div> |
| 67 | + <img v-lazy="{ref:'lazyRef', src:img}"> |
| 68 | + </div> |
| 69 | + </lazy-ref> |
| 70 | + </div> |
10 | 71 | <button @click="changeImg">Change img</button> |
11 | | - <button @click="changeShow">Change show</button> |
12 | 72 | </div> |
13 | 73 | </template> |
14 | 74 | <script> |
15 | | -import { LazyRef, Lazy } from '../../src/index'; |
16 | | -
|
17 | 75 | let i = 0; |
18 | 76 |
|
| 77 | +function genImgSrc() { |
| 78 | + return 'img/lenna.png?_t=' + Math.floor(Math.random() * 100000) + '.' + Date.now(); |
| 79 | +} |
| 80 | +
|
19 | 81 | export default { |
20 | 82 | data() { |
21 | 83 | return { |
22 | | - img: 'img/lena1.png', |
| 84 | + img: genImgSrc(), |
23 | 85 | show: true |
24 | 86 | }; |
25 | 87 | }, |
26 | 88 | methods: { |
27 | 89 | changeImg() { |
28 | | - this.img = 'img/lena' + (i++) + '.png'; |
| 90 | + this.img = genImgSrc(); |
29 | 91 | }, |
30 | 92 | changeShow() { |
31 | 93 | this.show = !this.show; |
| 94 | + }, |
| 95 | + changeTest() { |
| 96 | + this.test = !this.test; |
32 | 97 | } |
33 | | - }, |
34 | | - components: { |
35 | | - 'lazy-target': LazyRef |
36 | | - }, |
37 | | - directives: { |
38 | | - 'lazy': Lazy |
39 | 98 | } |
40 | 99 | }; |
| 100 | +
|
| 101 | +
|
| 102 | +
|
41 | 103 | </script> |
0 commit comments