欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實(shí)現(xiàn)拖拽窗口功能

 更新時(shí)間:2022年04月08日 13:33:40   作者:橡皮擦不掉的  
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)拖拽窗口功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue拖拽窗口簡(jiǎn)單實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

效果

實(shí)現(xiàn)代碼

<template>
? <transition>
? ? <!-- ? ?綁定style中top和left-->
? ? <div class="moveBox" :style="position" v-show="show">
? ? ? <div
? ? ? ? class="moveHead"
? ? ? ? @mousedown="mousedown"
? ? ? ? @mousemove="mousemove"
? ? ? ? @mouseup="mouseup"
? ? ? ? @mouseleave="mousemove"
? ? ? ></div>
? ? ? <!-- ? ? ?關(guān)閉按鈕-->
? ? ? <div class="close" @click="toggleShow">×</div>
? ? ? <div class="content">
? ? ? ? <!--插槽-->
? ? ? ? <slot></slot>
? ? ? </div>
? ? </div>
? </transition>
</template>

<script>
export default {
? name: "moveBox",
? data() {
? ? return {
? ? ? show: true,//是否顯示
? ? ? x: 100,//left:x
? ? ? y: 50,//top:y
? ? ? leftOffset: 0,//鼠標(biāo)距離移動(dòng)窗口左側(cè)偏移量
? ? ? topOffset: 0,//鼠標(biāo)距離移動(dòng)窗口頂部偏移量
? ? ? isMove: false,//是否移動(dòng)標(biāo)識(shí)
? ? };
? },
? computed: {
? ? //top與left加上px
? ? position() {
? ? ? return `top:${this.y}px;left:${this.x}px;`;
? ? },
? },
? methods: {
? ? //控制打開(kāi)關(guān)閉
? ? toggleShow() {
? ? ? this.x = 100;
? ? ? this.y = 50;
? ? ? this.show = !this.show;
? ? },
? ? mousedown(event) {
? ? ? //鼠標(biāo)按下事件
? ? ? this.leftOffset = event.offsetX;
? ? ? this.topOffset = event.offsetY;
? ? ? this.isMove = true;
? ? },
? ? //鼠標(biāo)移動(dòng)
? ? mousemove(event) {
? ? ? if (!this.isMove) {
? ? ? ? return;
? ? ? }
? ? ? this.x = event.clientX - this.leftOffset;
? ? ? this.y = event.clientY - this.topOffset;
? ? },
? ? //鼠標(biāo)抬起
? ? mouseup() {
? ? ? this.isMove = false;
? ? },
? },
};
</script>

<style lang="less" scoped>
.moveBox {
? width: 500px;
? height: 300px;
? position: fixed;
? box-shadow: 0 0 5px 3px #95a5a6;
? .moveHead {
? ? height: 30px;
? ? background-color: #bdc3c7;
? ? cursor: move;
? }
? .close {
? ? position: absolute;
? ? right: 0;
? ? top: 0;
? ? line-height: 30px;
? ? font-size: 24px;
? ? cursor: pointer;
? ? display: block;
? ? width: 30px;
? ? height: 30px;
? ? text-align: center;
? }
}
.v-enter,
.v-leave-to {
? opacity: 0;
? transform: scale(0.5);
}
.content {
? padding: 10px;
}
.v-enter-active,
.v-leave-active {
? transition: all 0.5s ease;
}
</style>

使用

<template>
? <div class="home">
? ? <button @click="$refs.moveBox.toggleShow()">toggle moveBox</button>
? ? <move-box ref="moveBox">
? ? ? Hello World
? ? </move-box>
? </div>
</template>

代碼沒(méi)什么難度,主要是使用了定位,在鼠標(biāo)移動(dòng)事件中定義top和left值。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue通過(guò)接口直接下載java生成好的Excel表格案例

    vue通過(guò)接口直接下載java生成好的Excel表格案例

    這篇文章主要介紹了vue通過(guò)接口直接下載java生成好的Excel表格案例
    2020-10-10
  • vue調(diào)用高德地圖實(shí)例代碼

    vue調(diào)用高德地圖實(shí)例代碼

    本篇文章主要介紹了vue調(diào)用高德地圖實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-04-04
  • 一文詳解Vue3響應(yīng)式原理

    一文詳解Vue3響應(yīng)式原理

    這篇文章主要介紹了一文詳解Vue3響應(yīng)式原理,文章通過(guò)與vue2.x?的響應(yīng)式做對(duì)比詳解展現(xiàn)出了Vue3響應(yīng)式原理詳情,感興趣的小伙伴可以參考一下
    2022-06-06
  • vue3如何實(shí)現(xiàn)單點(diǎn)登錄

    vue3如何實(shí)現(xiàn)單點(diǎn)登錄

    這篇文章主要介紹了vue3如何實(shí)現(xiàn)單點(diǎn)登錄問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue實(shí)現(xiàn)模態(tài)框的通用寫(xiě)法推薦

    vue實(shí)現(xiàn)模態(tài)框的通用寫(xiě)法推薦

    下面小編就為大家分享一篇vue實(shí)現(xiàn)模態(tài)框的通用寫(xiě)法推薦,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • vue中render函數(shù)和h函數(shù)以及jsx的使用方式

    vue中render函數(shù)和h函數(shù)以及jsx的使用方式

    這篇文章主要介紹了vue中render函數(shù)和h函數(shù)以及jsx的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue.use源碼學(xué)習(xí)小結(jié)

    Vue.use源碼學(xué)習(xí)小結(jié)

    這篇文章主要介紹了Vue.use源碼學(xué)習(xí)小結(jié),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • Vue2.0組件間數(shù)據(jù)傳遞示例

    Vue2.0組件間數(shù)據(jù)傳遞示例

    本篇文章主要介紹了Vue2.0組件間數(shù)據(jù)傳遞示例,組件間數(shù)據(jù)傳遞主要是父子組件之間傳遞,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-03-03
  • Vite+Vue3使用MockJS的實(shí)現(xiàn)示例

    Vite+Vue3使用MockJS的實(shí)現(xiàn)示例

    寫(xiě)一些純前端的項(xiàng)目時(shí),自己造數(shù)據(jù)有些麻煩,于是我們可以利用mock造一些簡(jiǎn)單的數(shù)據(jù),來(lái)滿足我們的需求,本文主要介紹了Vite+Vue3使用MockJS的實(shí)現(xiàn)示例,感興趣的可以了解一下
    2024-01-01
  • Vue3?setup的注意點(diǎn)及watch監(jiān)視屬性的六種情況分析

    Vue3?setup的注意點(diǎn)及watch監(jiān)視屬性的六種情況分析

    這篇文章主要介紹了Vue3?setup的注意點(diǎn)及watch監(jiān)視屬性的六種情況,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-04-04

最新評(píng)論