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

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

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

一、實現(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;
                    // }
                    //阻止頁面的滑動默認事件
                    document.addEventListener(
                        "touchmove",
                        function () {
                            event.preventDefault();
                        },
                        false
                    );
                }
            },
            //鼠標釋放時候的函數(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端可拖動懸浮按鈕的文章就介紹到這了,更多相關(guān)vue拖動懸浮按鈕內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • axios取消請求的實踐記錄分享

    axios取消請求的實踐記錄分享

    今天小編就為大家?guī)硪黄猘xios取消請求的實踐記錄分享,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue3項目中使用自適應Rem示例

    Vue3項目中使用自適應Rem示例

    這篇文章主要為大家介紹了Vue3項目中使用自適應Rem示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-08-08
  • 使用Vue后如何針對搜索引擎做SEO優(yōu)化

    使用Vue后如何針對搜索引擎做SEO優(yōu)化

    本文介紹了Vue.js在SEO優(yōu)化方面的挑戰(zhàn),并提供了一些方法來解決這些問題,包括使用服務器端渲染、預渲染和使用VueRouter的History模式來生成靜態(tài)HTML頁面,以及添加meta信息和內(nèi)部鏈接來提高搜索引擎的索引和排名
    2025-02-02
  • Vue?quill-editor?編輯器使用及自定義toobar示例詳解

    Vue?quill-editor?編輯器使用及自定義toobar示例詳解

    這篇文章主要介紹了Vue quill-editor編輯器使用及自定義toobar示例詳解,這里講解編輯器quil-editor的知識結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2023-07-07
  • Vue起步(無cli)的啊教程詳解

    Vue起步(無cli)的啊教程詳解

    本文通過實例代碼給大家介紹了Vue起步(無cli)的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2019-04-04
  • mpvue寫一個CPASS小程序的示例

    mpvue寫一個CPASS小程序的示例

    這篇文章主要介紹了mpvue寫一個CPASS小程序的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • Vue實現(xiàn)自定義組件改變組件背景色(示例代碼)

    Vue實現(xiàn)自定義組件改變組件背景色(示例代碼)

    要實現(xiàn) Vue 自定義組件改變組件背景色,你可以通過 props 將背景色作為組件的一個屬性傳遞給組件,在組件內(nèi)部監(jiān)聽這個屬性的變化,并將其應用到組件的樣式中,下面通過示例代碼介紹Vue如何實現(xiàn)自定義組件改變組件背景色,感興趣的朋友一起看看吧
    2024-03-03
  • Vue實現(xiàn)省市區(qū)三級聯(lián)動el-select組件的示例代碼

    Vue實現(xiàn)省市區(qū)三級聯(lián)動el-select組件的示例代碼

    這篇文章主要為大家詳細介紹了Vue實現(xiàn)省市區(qū)三級聯(lián)動el-select組件的方法,文中的示例代碼講解詳細,具有一定的借鑒價值,需要的的可以參考一下
    2023-02-02
  • 使用vite搭建ssr活動頁架構(gòu)的實現(xiàn)

    使用vite搭建ssr活動頁架構(gòu)的實現(xiàn)

    本文主要介紹了使用vite搭建ssr活動頁架構(gòu),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • Vue vxe-table使用問題收錄小結(jié)

    Vue vxe-table使用問題收錄小結(jié)

    這篇文章主要為大家介紹了Vue vxe-table使用問題收錄小結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09

最新評論