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畫(huà)出帶箭頭的提示框效果,感興趣的朋友一起看看吧
通過(guò)css畫(huà)出帶箭頭的提示框
一、畫(huà)出一個(gè)提示框
<div id="notice"> </div> #notice { width: 150px; height: 175px; border: 1px solid #9D9D9D; /* 移動(dòng)到屏幕中間 方便查看*/ position: relative; left: 50%; right: 50%; }
效果
二、畫(huà)出一個(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ò)開(kāi)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)文章
vue3動(dòng)態(tài)路由解決刷新頁(yè)面空白或跳轉(zhuǎn)404問(wèn)題
這篇文章主要為大家詳細(xì)介紹了vue3如何通過(guò)動(dòng)態(tài)路由解決刷新頁(yè)面空白或跳轉(zhuǎn)404問(wèn)題,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2025-01-01基于vue+canvas的excel-like組件實(shí)例詳解
a vue component,基于vue的表格組件,主要解決大數(shù)據(jù)量的表格渲染性能問(wèn)題,使用canvas繪制表格,同時(shí)支持類(lèi)似excel的批量選中,復(fù)制黏貼刪除,實(shí)時(shí)編輯等功能.這篇文章主要介紹了基于vue+canvas的excel-like組件,需要的朋友可以參考下2017-11-11用Vue.js方法創(chuàng)建模板并使用多個(gè)模板合成
在本篇文章中小編給大家分享了關(guān)于如何使用Vue.js方法創(chuàng)建模板并使用多個(gè)模板合成的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。2019-06-06vue項(xiàng)目引入百度地圖BMapGL鼠標(biāo)繪制和BMap輔助工具
這篇文章主要為大家介紹了vue項(xiàng)目引入百度地圖BMapGL鼠標(biāo)繪制和BMap輔助工具的踩坑分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02Vue3中的setup執(zhí)行時(shí)機(jī)與注意點(diǎn)說(shuō)明
這篇文章主要介紹了Vue3中的setup執(zhí)行時(shí)機(jī)與注意點(diǎn)說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07vue-cli 3.x配置跨域代理的實(shí)現(xiàn)方法
這篇文章主要介紹了vue-cli 3.x配置跨域代理的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04