vue3 選中對(duì)話框時(shí)對(duì)話框右側(cè)出一個(gè)箭頭效果
vue3 選中對(duì)話框時(shí)對(duì)話框右側(cè)出一個(gè)箭頭
先看下做出的效果:

html代碼,其中l(wèi)istPlan.records是后臺(tái)拿到的數(shù)據(jù)進(jìn)行遍歷
<template>
<ul class="list">
<li style="height: 180px;width: 95%"
:key="index"
v-for="(item, index) in listPlan.records"
:style="liStyle(index)"
@click="selectItem(index,item.id)" >
<span v-if="selectedIndex === index" class="shixin"></span>
<span v-if="selectedIndex === index" class="kongxin"></span>
<div class="notice">
<div class="fsPnameDiv">
<div class="fsPname" >
{{ item.fsPname }}
</div>
<div v-if="item.fsStatus=='00'" style="color: #0a8fe9">
<span class="ant-badge-status-dot" style="background: rgb(68, 160, 239);"></span>
激活
</div>
<div v-if="item.fsStatus!='00'" style="color: rgb(208 213 217)">
<span class="ant-badge-status-dot" style="background: rgb(208 213 217);"></span>
禁用
</div>
</div>
<div style="margin-top: 5px">
每隔{{ item.fsExecinterval }} {{ item.fsExecintervaltype }} 執(zhí)行一次
</div>
<div style="margin-top: 5px">
創(chuàng)建時(shí)間:{{ item.createTime }}
</div>
</div>
</li>
</ul>
</template>ts代碼
原理:選中時(shí)判斷比較選中的下標(biāo)是和循環(huán)中的游標(biāo)一致改變樣式
let planId=null;
// 當(dāng)前選中的索引
const selectedIndex = ref(-1);
// 動(dòng)態(tài)生成 li 的樣式
const liStyle = (index: number) => {
return {
border: '1px solid #ccc', // 添加邊框
borderRadius: '5px',
padding: '10px', // 內(nèi)邊距
margin: '5px 0', // 外邊距
cursor: 'pointer', // 鼠標(biāo)指針樣式
position: 'relative', // 相對(duì)定位,用于放置箭頭
borderLeft: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc', // 選中時(shí)的框樣式
borderBottom: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc',
borderTop: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc',
borderRight: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc',
};
};css
原理:無(wú)大小的div設(shè)置30px的邊框全透明,再單獨(dú)設(shè)置要顯示一側(cè)邊框的顏色和大框一致
<style lang="less" scoped>
.notice{
align-items: flex-start;
display: flex;
flex-direction: column;
padding: 8px 8px 12px;
}
.shixin {
border: 10px solid transparent;
border-left-color: #095ff0;
position: absolute;
top: 45%;
right: -20px;
}
.kongxin {
border: 10px solid transparent;
border-left-color: #fff;
position: absolute;
top: 45%;
right: -18px;
}
</style>下面給大家介紹通過(guò)css畫出帶箭頭的提示框效果,感興趣的朋友一起看看吧
通過(guò)css畫出帶箭頭的提示框
一、畫出一個(gè)提示框
<div id="notice">
</div>
#notice {
width: 150px;
height: 175px;
border: 1px solid #9D9D9D;
/* 移動(dòng)到屏幕中間 方便查看*/
position: relative;
left: 50%;
right: 50%;
}效果

二、畫出一個(gè)實(shí)心箭頭
原理:無(wú)大小的div設(shè)置30px的邊框全透明,再單獨(dú)設(shè)置要顯示一側(cè)邊框的顏色和大框一致
<div id="notice">
<div id="shixin"></div>
</div>
#shixin {
border: 30px solid transparent;
border-right-color: #9D9D9D; /*顏色和#notice框一致*/
position: absolute;
top: 10px;
left: -60px;
}
三、用一個(gè)空心div覆蓋在上面,只漏出1px的左邊兩個(gè)邊
<div id="notice">
<div id="shixin"></div>
<div id="kongxin"></div>
</div>
#kongxin {
border: 30px solid transparent;
border-right-color: #fff;
position: absolute;
top: 10px;
left: -59px; /**/
}
完整代碼
<style>
#notice {
width: 150px;
height: 175px;
border: 1px solid #9D9D9D;
/* 移動(dòng)到屏幕中間 方便查看*/
position: relative;
left: 50%;
right: 50%;
}
#shixin {
border: 30px solid transparent;
border-right-color: #9D9D9D; /*和#notice框一致*/
position: absolute;
top: 10px;
left: -60px;
}
#kongxin {
border: 30px solid transparent;
border-right-color: #fff; /*空心,和背景色一致*/
position: absolute;
top: 10px;
left: -59px; /*和實(shí)心框錯(cuò)開1px 漏出箭頭左邊兩邊*/
}
</style>
<div id="notice">
<div id="shixin"></div>
<div id="kongxin"></div>
</div>到此這篇關(guān)于vue3 選中對(duì)話框時(shí)對(duì)話框右側(cè)出一個(gè)箭頭效果的文章就介紹到這了,更多相關(guān)vue3對(duì)話框右側(cè)出一個(gè)箭頭內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue中漸進(jìn)過(guò)渡效果實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了vue中漸進(jìn)過(guò)渡效果的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼
這篇文章主要介紹了VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼,文中同時(shí)給大家提到了v-on:click獲取當(dāng)前事件對(duì)象元素的方法,需要的朋友可以參考下2018-08-08
vue實(shí)現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能示例
這篇文章主要介紹了vue實(shí)現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能,涉及vue.js表單事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-01-01
vue3開啟攝像頭并進(jìn)行拍照的實(shí)現(xiàn)示例
本文主要介紹了vue3開啟攝像頭并進(jìn)行拍照的實(shí)現(xiàn)示例,主要是使用navigator.mediaDevices.getUserMedia這個(gè)API來(lái)實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
vue.js圖片轉(zhuǎn)Base64上傳圖片并預(yù)覽的實(shí)現(xiàn)方法
這篇文章主要介紹了vue.js圖片轉(zhuǎn)Base64上傳圖片并預(yù)覽的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
讓webpack+vue-cil項(xiàng)目不再自動(dòng)打開瀏覽器的方法
今天小編就為大家分享一篇讓webpack+vue-cil項(xiàng)目不再自動(dòng)打開瀏覽器的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09
Vue實(shí)現(xiàn)動(dòng)態(tài)查詢規(guī)則生成組件
今天我們來(lái)給大家介紹下在Vue開發(fā)中我們經(jīng)常會(huì)碰到的一種需求場(chǎng)景,本文主要介紹了Vue動(dòng)態(tài)查詢規(guī)則生成組件,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05

