vue實現(xiàn)鼠標懸浮框效果
本文實例為大家分享了vue實現(xiàn)鼠標懸浮框效果的具體代碼,供大家參考,具體內(nèi)容如下
效果:

html:
<div ? @mouseenter="enter"? ? @mouseleave="leave"? ? @mousemove="move" > 鼠標觸碰元素 </div> ? <div v-show="popUpShow" class="hover_con" :style="positionStyle"> 懸浮框 </div>
js:
export default {
? ? name: '',
? ? data() {
? ? ? return {
? ? ? ? popUpShow:false,
? ? ? ? positionStyle:{top:'0px',left:'0px'}
? ? ? }
? ? },
? ? methods: {
? ? ? enter() {
? ? ? ? this.popUpShow = true
? ? ? },
? ? ? leave() {
? ? ? ? this.popUpShow = false
? ? ? },
? ? ? move(event) {
? ? ? ? const x = event.pageX + 15 + 'px'
? ? ? ? const y = event.pageY + 10 + 'px'
? ? ? ? this.positionStyle = { top: y, left: x } ?
? ? ? }
? ? }
}css:
.hover_con{
? position: fixed;
? max-width: 220px;
? padding: 10px;
? border: 1px solid #666;
? background: #ccc;
}關于offsetX、offsetY、clientX、clientY、pageX、pageY、screenX、screenY的區(qū)別
offsetX、offsetY: 鼠標相對于事件源元素(srcElement)的X,Y坐標
clientX、clientY: 鼠標相對于瀏覽器窗口可視區(qū)域的X,Y坐標(窗口坐標),可視區(qū)域不包括工具欄和滾動條。
pageX、pagey: 類似于event.clientX、event.clientY,但它們使用的是文檔坐標而非窗口坐標。這2個屬性不是標準屬性,但得到了廣泛支持。IE事件中沒 有這2個屬性
screenX、screenY: 鼠標相對于用戶顯示器屏幕左上角的X,Y坐標。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue動態(tài)生成新表單并且添加驗證校驗規(guī)則方式
這篇文章主要介紹了vue動態(tài)生成新表單并且添加驗證校驗規(guī)則方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10
Element-ui tree組件自定義節(jié)點使用方法代碼詳解
本文通過實例代碼給大家介紹了Element-ui tree組件自定義節(jié)點使用方法 ,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09
Vue通過WebSocket建立長連接的實現(xiàn)代碼
這篇文章主要介紹了Vue通過WebSocket建立長連接的實現(xiàn)代碼,文中給出了問題及解決方案,需要的朋友可以參考下2019-11-11

