Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8957

Nuxtでスマホアプリのようにsplash screenを表示させる方法

$
0
0
こんな感じ はじめに Nuxtで作ったwebアプリで、スマホアプリのsplash screen(👇のような起動時に表示される画像)を表示させたいと思いました。 よくあるローディング画面とは違って、必ず指定した秒数だけ表示させるようにしたかったので色々と調べた結果をここに記録します!! splash screen用の画面 最初の画面が表示される前に、ふんわりとロゴが表示されます。 components/LoadingScreen.vue <template> <div :class="{ loader: true, fadeout: !isLoading }"> <div class="page-container"> <img class="splash" src="@/assets/images/Logo.png" /> </div> </div> </template> <script lang="ts"> import Vue from "vue"; export default Vue.extend({ name: "LoadingScreen", props: ["isLoading"], }); </script> <style scoped> .page-container { max-width: 500px; width: 100%; margin: auto; } .loader { background-color: #ffffff; bottom: 0; color: white; display: flex; align-items: center; text-align: center; left: 0; overflow: hidden; position: fixed; right: 0; top: 0; } .splash { width: 150px; } .fadeout { animation: fadeout 2s forwards; } @keyframes fadeout { to { opacity: 0; visibility: hidden; } } </style> LoadingScreen.vueを一番最初に表示させる Nuxtで一番上の階層?にあるdefault.vueを編集。 これでindex.vueが読み込まれる前にsplash screenっぽい感じで、ロゴ画像をふんわりと表示させることに成功しました! layouts/default.vue <template> <div> <LoadingScreen :isLoading="isLoading" /> <transition name="fade" v-if="!isLoading"> <Nuxt /> </transition> </div> </template> <script> const LoadingScreen = () => import("../components/LoadingScreen.vue"); export default { components: { LoadingScreen, }, data() { return { isLoading: true, }; }, mounted() { setTimeout(() => { this.isLoading = false; }, 1000); }, }; </script> <style scoped> .fade-enter-active, .fade-leave-active { transition: opacity 1s; } .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ { opacity: 0; } </style> 参考

Viewing all articles
Browse latest Browse all 8957

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>