HTML代码:
<div id="dynamicIsland" class="dynamic-island" :class="active_or_inactive" :style="{opacity:opacity}" @mouseover="mouseover" @mouseout="mouseout" ref="dynamic_island">
<img :src="msg_data?.image ? msg_data.image : default_data.img" alt="通知图标" width="30" height="30">
<div class="island-content">
<div class="bars">
<p class="content-text" v-text="msg_data?.msg ? msg_data.msg : default_data.msg"></p>
<div v-for="i in 7" class="bar"></div>
</div>
</div>
</div>
CSS代码:
.dynamic-island {
position: fixed;
top: 80px;
left: 50%;
transform: translateX(-50%) scale(0);
transform-origin: center;
width: auto;
max-width: 80%;
height: 40px;
background-color: #000;
border-radius: 25px;
color: white;
display: flex;
align-items: center;
justify-content: space-between;
transition: transform 0.4s ease-in-out, height 0.6s ease-in-out, border-radius 0.6s ease-in-out, box-shadow 0.5s ease-in-out, opacity 0.5s ease-in-out;
overflow: visible;
z-index: 1000;
padding-left: 35px;
padding-right: 20px;
opacity: 0;
box-shadow: 0 0px 10px rgba(0, 0, 0, 0.45);
}
.island-content, .dynamic-island img {
filter: blur(10px);
transition: filter 0.8s ease-in-out;
}
.island-content {
opacity: 0;
transition: opacity 0.9s ease-in-out, filter 0.8s ease-in-out;
font-weight: bold;
flex-grow: 1;
text-align: right;
width: 100%;
}
.bars {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 3px;
transition: margin 0.8s ease-in-out, margin 0.8s ease-in-out, filter 0.8s ease-in-out;
}
.content-text{
line-height: 50px; margin: 0; font-size: 12px; padding-right: 10px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.bar {
line-height: 50px;
width: 2px;
height: 13px;
background-color: green;
animation: bounce 1s infinite ease-in-out;
animation-direction: alternate;
}
@keyframes bounce {
0% {
transform: scaleY(0.3);
background-color: green;
}
50% {
transform: scaleY(1);
background-color: orange;
}
100% {
transform: scaleY(0.3);
background-color: green;
}
}
.bar:nth-child(1) { animation-duration: 1s; }
.bar:nth-child(2) { animation-duration: 0.9s; }
.bar:nth-child(3) { animation-duration: 0.8s; }
.bar:nth-child(4) { animation-duration: 0.7s; }
.bar:nth-child(5) { animation-duration: 0.6s; }
.bar:nth-child(6) { animation-duration: 0.9s; }
.bar:nth-child(7) { animation-duration: 0.7s; }
.dynamic-island img {
position: absolute;
left: 10px;
width: 20px;
height: 20px;
object-fit: cover;
transition: height 0.8s ease-in-out, width 0.8s ease-in-out, filter 0.8s ease-in-out;
border-radius:50%;
}
.dynamic-island:hover img {
width: 30px;
height: 30px;
}
.dynamic-island.active .island-content {
opacity: 1;
}
.dynamic-island.active .island-content, .dynamic-island.active img {
filter: blur(0);
}
.dynamic-island:hover {
height: 60px;
border-radius: 50px;
}
.dynamic-island:hover .bars{
margin-left: 15px;
}
.dynamic-island.active {
transform: translateX(-50%) scale(1);
opacity: 1;
}
.dynamic-island.inactive {
transform: translateX(-50%) scale(0);
opacity: 0;
}
JS代码:
var dynamicIsland = new Vue({
el: "#dynamicIsland",
data: {
closeTimeout:null,
animationTimeout:null,
active_or_inactive:'',
opacity:0,
msg_data:{},
default_data:{
img:b2_global.ahap_lingdong_island_img,
msg:'欢迎访问' + (b2_global.ahap_post_title ? '['+ b2_global.ahap_post_title +']' : b2_global.site_name)
}
},
mounted(){
if(this.$refs.dynamic_island){
this.open();
}
},
methods: {
open(msg){
this.msg_data = msg;
clearTimeout(this.closeTimeout);
clearTimeout(this.animationTimeout);
setTimeout(()=>{
this.opacity = 1;
this.active_or_inactive = 'active';
}, 500);
this.closeTimeout = setTimeout(() => {
this.close();
}, msg && msg.time ? (msg.time * 1000) : 4000);
},
close(){
this.active_or_inactive = 'inactive';
this.animationTimeout = setTimeout(() => {
this.opacity = 0;
}, 600);
},
mouseover(){
clearTimeout(this.closeTimeout);
clearTimeout(this.animationTimeout);
},
mouseout(){
this.closeTimeout = setTimeout(() => {
this.close();
}, 1500);
}
}
});
注:文本的代码使用为半成品,如需使用请自行引入相关依赖自行更改相关代码。
一、本站上的部份代码及教程来源于互联网,仅供网友学习交流。如有侵权,无意侵害您的权益,请发送邮件至zhangshen#ahap.cn或点击右侧 联系我们,我们将尽快处理。
二、请勿将购买的资源教程转载或分享与他人!
二、请勿将购买的资源教程转载或分享与他人!