写在前面
移动端页面,有时候会出现一些固定定位在底部图标,比如购物车等。这时候如果添加一个滑动页面,图标透明度变低,同时 移动到屏幕边进行隐藏,效果如下。
所用原理
监听滑动事件,每次进行滑动时,触发动画,添加定时器,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实现固定定位图标滑动隐藏效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Vue实现固定定位图标滑动隐藏效果”评论...
更新动态
2025年10月24日
2025年10月24日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
