最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼

 更新時(shí)間:2024年02月02日 11:25:43   作者:Best_Liu~  
這篇文章主要介紹了VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼,通過實(shí)例代碼介紹了父頁面引用的方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

一、實(shí)現(xiàn)效果:

二、FloatButton.vue

<template>
    <div>
        <div class="sssss">
            <div class="callback float" @mousedown="down" @touchstart="down" @mousemove="move" @touchmove="move" @mouseover="over" @mouseout="out"
                @mouseup="end" @touchend="end" ref="fu" style="color: #1a1919;">
                <el-button circle @click="screen()">
                    {{name}}
                </el-button>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        name: "suspensionBall",
        props: {
            name: {
                type: String,
                default: '打開全屏'
            },
        },
        data() {
            return {
                left: 0,
                top: 40,
                bg: 1,
                menu: false,
                isLoading: false,
                flags: false, //控制使用
                position: {
                    x: 0,
                    y: 0,
                },
                nx: "",
                ny: "",
                dx: "",
                dy: "",
                xPum: "",
                yPum: "",
                movb: 1,
                num: 1,
            };
        },
        created() { },
        mounted() {
            this.left = this.$refs.fu.offsetLeft - 750;
        },
        methods: {
            out2() {
                this.menu = false;
            },
            over2() { },
            out() {
                this.bg = 2;
            },
            over() {
                this.menu = true;
                this.num = 2;
                this.bg = 1;
            },
            callback() {
                this.$router.go(-1);
            },
            onRefresh() {
                // window.location.reload();
                setTimeout((res) => {
                    console.log(res);
                    this.isLoading = false;
                }, 1000);
            },
            down() {
                this.flags = true;
                var touch;
                if (event.touches) {
                    touch = event.touches[0];
                } else {
                    touch = event;
                }
                this.position.x = touch.clientX;
                this.position.y = touch.clientY;
                this.dx = this.$refs.fu.offsetLeft;
                this.dy = this.$refs.fu.offsetTop;
            },
            move() {
                if (this.flags) {
                    this.movb = 2;
                    this.menu = false;
                    var touch;
                    if (event.touches) {
                        touch = event.touches[0];
                    } else {
                        touch = event;
                    }
                    this.nx = touch.clientX - this.position.x;
                    this.ny = touch.clientY - this.position.y;
                    this.xPum = this.dx + this.nx;
                    this.yPum = this.dy + this.ny;
                    let width = window.innerWidth - this.$refs.fu.offsetWidth; //屏幕寬度減去自身控件寬度
                    let height = window.innerHeight - this.$refs.fu.offsetHeight; //屏幕高度減去自身控件高度
                    this.xPum < 0 && (this.xPum = 0);
                    this.yPum < 0 && (this.yPum = 0);
                    this.xPum > width && (this.xPum = width);
                    this.yPum > height && (this.yPum = height);
                    // if (this.xPum >= 0 && this.yPum >= 0 && this.xPum<= width &&this.yPum<= height) {
                    this.$refs.fu.style.left = this.xPum + "px";
                    this.$refs.fu.style.top = this.yPum + "px";
                    this.left = this.xPum - 750;
                    this.top = this.yPum;
                    // }
                    //阻止頁面的滑動(dòng)默認(rèn)事件
                    document.addEventListener(
                        "touchmove",
                        function () {
                            event.preventDefault();
                        },
                        false
                    );
                }
            },
            //鼠標(biāo)釋放時(shí)候的函數(shù)
            end() {
                this.flags = false;
            },
            screen() {
                this.$emit("changeClick");
            },
        },
    };
</script>
<style scoped>
    .callback {
        position: fixed;
        width: 200px;
        height: 20px;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        top: 200px;
        left: 90%;
        z-index: 99999;
    }
    .float {
        position: fixed;
        touch-action: none;
        text-align: center;
        border-radius: 24px;
        line-height: 48px;
        color: white;
    }
    .menuclass {
        text-align: left;
        position: absolute;
        color: #000;
        width: 764px;
        background: #ffffff;
        box-shadow: 0px 6px 26px 1px rgba(51, 51, 51, 0.16);
        padding: 20px;
    }
    .sssss {
        position: relative;
        background-color: #000;
        right: 0;
        z-index: 99999;
    }
    .titlea {
        font-size: 18px;
        font-family: Microsoft YaHei-Bold, Microsoft YaHei;
        font-weight: bold;
        color: #333333;
    }
    .boxa {
        display: flex;
        flex-wrap: wrap;
        margin-top: 20px;
        z-index: 999999;
    }
    .item {
        width: 168px;
        height: 75px;
        border-radius: 4px 4px 4px 4px;
        font-size: 16px;
        font-family: Microsoft YaHei-Bold, Microsoft YaHei;
        font-weight: bold;
        color: #ffffff;
        text-align: center;
        margin-left: 7px;
        line-height: 75px;
    }
</style>

三、父頁面引用

<template>
    <div>
        <float-button ref="floatButton" :name="buttonName" @changeClick="screen" />
    </div>
</template>
<script>
import FloatButton from './chart/FloatButton'
export default {
        name: 'Index',
        components: {
            FloatButton
        },
}
</script>

到此這篇關(guān)于VUE PC端可拖動(dòng)懸浮按鈕的文章就介紹到這了,更多相關(guān)vue拖動(dòng)懸浮按鈕內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

德保县| 张家川| 亳州市| 织金县| 孙吴县| 宝山区| 泸定县| 吴桥县| 东方市| 桦南县| 广州市| 沧州市| 吉木萨尔县| 色达县| 工布江达县| 怀仁县| 康马县| 甘孜县| 临泉县| 曲沃县| 株洲县| 兴山县| 车险| 朝阳区| 株洲县| 府谷县| 龙江县| 宜川县| 蒙城县| 广水市| 平湖市| 凤山县| 罗城| 卓资县| 大邑县| 茌平县| 隆德县| 合肥市| 洛川县| 沿河| 郴州市|