标签:name show app month item 源码 border 下拉框 hd
app直播源码,弹出下拉框时可以点击任意区域关闭
1.实现原理
mounted:初始化页面完成后,再对html的dom节点进行一些需要的操作组件
添加点击事件监听document.addEventListener,假设点击区域不再该区域上,关闭弹框
2.实现代码
<template>
<div>
<div>
<div>
<div
class="hd_sel flex-row j_b"
@click="show_month = !show_month"
ref="s1"
>
<div>{{ current_month }}</div>
<div
:class="{ top: show_month, bot: !show_month }"
></div>
</div>
</div>
<div>
<div v-show="show_month">
<div
v-for="(item, index) in month_list"
:class="{ drop_hd_ative: current_month == item.name }"
:key="index"
@click="choseItem(item, index)"
>
{{ item.name }}
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "dropItem",
data() {
return {
current_month: "All",
show_month: false,
month_list: [
{
name: "All",
},
{
name: "2022-1",
},
{
name: "2022-2",
},
],
};
},
mounted() {
document.addEventListener(
"click",
(e) => {
let s1 = this.$refs.s1;
if (!s1.contains(e.target)) {
this.show_month = false;
}
},
true
);
},
methods: {
choseItem(e) {
this.current_month = e.name;
this.show_month = false;
},
},
};
</script>
<style scoped>
.drop_hd_ative {
color: #fff !important;
}
.drop_hd_item {
line-height: 30px;
color: #333;
}
.drop_hd {
position: absolute;
width: 200px;
min-height: 30px;
box-sizing: border-box;
padding: 10px;
background: #fff;
left: 0;
top: 3px;
border-radius: 5px;
z-index: 99;
box-shadow: 5px 5px 5px #ccc;
cursor: pointer;
}
.hd_e {
position: relative;
}
.hd_sel {
margin-top: 50px;
min-width: 200px;
height: 32px;
background: rgba(243, 243, 243);
border-radius: 8px;
box-sizing: border-box;
padding: 0 16px;
font-size: 14px;
font-weight: 500;
position: relative;
cursor: pointer;
}
.arrow {
border-width: 6px;
border-bottom: 0;
border-color: #fff transparent transparent transparent;
border-style: solid;
width: 0;
height: 0;
transition: transform 0.3s;
margin-left: 10px;
&.bot {
transform: rotate(0deg);
}
&.top {
transform: rotate(-180deg);
}
}
</style>
以上就是 app直播源码,弹出下拉框时可以点击任意区域关闭,更多内容欢迎关注之后的文章
标签:name,show,app,month,item,源码,border,下拉框,hd 来源: https://www.cnblogs.com/yunbaomengnan/p/16305388.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。