Last active
August 4, 2020 01:38
-
-
Save PKTseng/472e4cbc62ff4f6f35d3438ff5b44714 to your computer and use it in GitHub Desktop.
偵聽圖片 onload 事件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<h2 v-if="loading">Loading</h2> | |
<h2 v-else>complete</h2> | |
<img | |
:class="imgClass" | |
@load="loading = false" | |
src="https://picsum.photos/500/300" alt=""> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
el:"#app", | |
data:{ | |
loading: true, | |
}, | |
computed:{ | |
imgClass(){ | |
if(this.loading){ | |
return 'img hide'; | |
}else{ | |
return 'img'; | |
} | |
}, | |
}, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.img.hide{ | |
opacity: 0; | |
} | |
.img{ | |
transition: opacity 1.5s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment