明霞山资源网 Design By www.htccd.com
写在前面
移动端页面,有时候会出现一些固定定位在底部图标,比如购物车等。这时候如果添加一个滑动页面,图标透明度变低,同时 移动到屏幕边进行隐藏,效果如下。
所用原理
监听滑动事件,每次进行滑动时,触发动画,添加定时器,1.4s后显示该图标。具体代码如下:
<template>
<section class="fixed-icon"
:style="{ bottom: bottom + 'rem' }"
:class="[ !transition "
@click="event">
<slot></slot>
</section>
</template>
<script>
export default {
name: 'fixedIcon',
props: {
bottom: { // 改图标距离底部距离 单位 rem
type: Number,
default: 3,
},
},
data () {
return {
transition: true, // 是否触发动画
timer: null, // 定时器
};
},
methods: {
event() {
this.$emit('clickEvent'); // 绑定点击图表时间
},
handleScroll () { // 每次滑动都会执行函数
this.transition = false;
if (this.timer) { // 判断是否已存在定时器
clearTimeout(this.timer);
}
this.timer = setTimeout(() => { // 创建定时器,1.4s后图标回归原位置
this.transition = true;
}, 1400);
}
},
mounted () {
window.addEventListener('scroll', this.handleScroll); // 监听页面滑动
}
};
</script>
<style scoped lang="scss">
/*@media only screen and (min-width:750px){html{font-size:20px}} */
.fixed-icon{
position: fixed;
z-index: 1100;
right: 1.7rem;
display: flex;
justify-content: center;
align-items: center;
height: 4.1rem;
width: 4.1rem;
border-radius: 50%;
background-color: rgba(128, 128, 128, 0.8);
transition: 0.7s ease-in-out;
}
.fixed-transition{
right: -2.05rem;
opacity: 0.4;
transition: 1s ease-in-out;
}
</style>
引入代码如下:
<template>
<section class="content">
<fixed-icon :bottom="3" @clickEvent="chat">
<i class="icon-chat"></i>
</fixed-icon>
</section>
</template>
<script>
import fixedIcon from './components/fixedIcon.vue';
export default {
name: 'test',
components: {
fixedIcon
},
data () {
return {
};
},
methods: {
chat() { // 图标点击事件
console.log('你好');
},
},
mounted() {
document.title = 'Vue制作固定定位图标滑动隐藏效果';
},
};
</script>
<style scoped lang="scss">
.content{
height: 200vh;
}
.icon-chat{
width: 2rem;
height: 1.9rem;
background: url('http://pfpdwbdfy.bkt.clouddn.com/image/test/fixedIconTranstion/wechat.png') no-repeat;
background-size: 2rem 1.9rem;
}
</style>
github代码
总结
以上所述是小编给大家介绍的Vue实现固定定位图标滑动隐藏效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
