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

html代碼,其中l(wèi)istPlan.records是后臺拿到的數(shù)據(jù)進行遍歷
<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)建時間:{{ item.createTime }}
</div>
</div>
</li>
</ul>
</template>ts代碼
原理:選中時判斷比較選中的下標是和循環(huán)中的游標一致改變樣式
let planId=null;
// 當前選中的索引
const selectedIndex = ref(-1);
// 動態(tài)生成 li 的樣式
const liStyle = (index: number) => {
return {
border: '1px solid #ccc', // 添加邊框
borderRadius: '5px',
padding: '10px', // 內(nèi)邊距
margin: '5px 0', // 外邊距
cursor: 'pointer', // 鼠標指針樣式
position: 'relative', // 相對定位,用于放置箭頭
borderLeft: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc', // 選中時的框樣式
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
原理:無大小的div設置30px的邊框全透明,再單獨設置要顯示一側(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>下面給大家介紹通過css畫出帶箭頭的提示框效果,感興趣的朋友一起看看吧
通過css畫出帶箭頭的提示框
一、畫出一個提示框
<div id="notice">
</div>
#notice {
width: 150px;
height: 175px;
border: 1px solid #9D9D9D;
/* 移動到屏幕中間 方便查看*/
position: relative;
left: 50%;
right: 50%;
}效果

二、畫出一個實心箭頭
原理:無大小的div設置30px的邊框全透明,再單獨設置要顯示一側(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;
}
三、用一個空心div覆蓋在上面,只漏出1px的左邊兩個邊
<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;
/* 移動到屏幕中間 方便查看*/
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; /*和實心框錯開1px 漏出箭頭左邊兩邊*/
}
</style>
<div id="notice">
<div id="shixin"></div>
<div id="kongxin"></div>
</div>到此這篇關(guān)于vue3 選中對話框時對話框右側(cè)出一個箭頭效果的文章就介紹到這了,更多相關(guān)vue3對話框右側(cè)出一個箭頭內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue實現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能示例
這篇文章主要介紹了vue實現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能,涉及vue.js表單事件響應及頁面元素屬性動態(tài)操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2019-01-01
vue.js圖片轉(zhuǎn)Base64上傳圖片并預覽的實現(xiàn)方法
這篇文章主要介紹了vue.js圖片轉(zhuǎn)Base64上傳圖片并預覽的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
讓webpack+vue-cil項目不再自動打開瀏覽器的方法
今天小編就為大家分享一篇讓webpack+vue-cil項目不再自動打開瀏覽器的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
Vue實現(xiàn)動態(tài)查詢規(guī)則生成組件
今天我們來給大家介紹下在Vue開發(fā)中我們經(jīng)常會碰到的一種需求場景,本文主要介紹了Vue動態(tài)查詢規(guī)則生成組件,需要的朋友們下面隨著小編來一起學習學習吧2021-05-05

