Vue.jsを使ってポップアップ風の画面を作ってみました。
CSSで表示前・後のデザインを作り、クリックイベントで切り替えています。
↓以下が実際のソースサンプルです。
▼JavaScript(Vue.js)
document.addEventListener("DOMContentLoaded", function (event) {
new Vue({
el: '#app',
data: {
popUp: false,
productData: {
is_featured: false
}
},
methods: {
resetForm: function () {
this.productData = {
is_featured: false
}
},
cancel: function() {
this.popUp = false;
this.resetForm();
}
}
});
});
▼SCSS
body {
background-color: #FFF8E7;
}
.container {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
.add-product {
transition: all 0.3s ease;
background-color: #8f6552;
height: 144px;
width: 144px;
border-radius: 72px;
box-shadow: 0 4px 16px 0 rgba(0, 0, 0, .07);
cursor: pointer;
.button {
text-align: center;
line-height: 144px;
font-weight: bold;
color: #FFF8E7;
}
.form {
transition: none;
opacity: 0;
height: 0;
overflow: hidden;
}
&.open {
background-color: #8f6552;
padding: 18px 32px;
border-radius: 5px;
width: 420px;
height: 398px;
cursor: default;
.form {
opacity: 1;
transition: opacity 0.1s ease;
transition-delay: 0.3s;
height: auto;
}
.form_text {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 420px;
height: 398px;
p {
font-size: 32px;
font-weight: bold;
color: #FFF8E7;
}
span {
font-size: 12px;
&:hover {
text-decoration: underline;
cursor: pointer;
}
}
}
}
}
▼HTML
<body>
<div class="container" id="app">
<div class="add-product" :class="{'open': popUp}">
<div class="button" v-show="!popUp" @click="popUp = true">クリック</div>
<div class="form" @submit="cancel()">
<div class="form_text">
<p>Hello!!</p>
<span @click="cancel()">Cancel</span>
</div>
</div>
</div>
</div>
</body>
今回、参考にさせていただいたのは、
『iPhoneのようにフリック操作でスクロールできるjQueryプラグインつくった – テクメモ』さんです。
ありがとうございます。
