国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【sgDragSize】自定義拖拽修改DIV尺寸組件,適用于窗體大小調(diào)整

這篇具有很好參考價(jià)值的文章主要介紹了【sgDragSize】自定義拖拽修改DIV尺寸組件,適用于窗體大小調(diào)整。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

【sgDragSize】自定義拖拽修改DIV尺寸組件,適用于窗體大小調(diào)整,Vue.js,JavaScript&TypeScript,前端,javascript,html

核心原理就是在四條邊、四個(gè)頂點(diǎn)加上透明的div,給不同方向提供按下移動(dòng)鼠標(biāo)監(jiān)聽?,對(duì)應(yīng)計(jì)算寬度高度、坐標(biāo)變化?【sgDragSize】自定義拖拽修改DIV尺寸組件,適用于窗體大小調(diào)整,Vue.js,JavaScript&TypeScript,前端,javascript,html

特性:文章來源地址http://www.zghlxwxcb.cn/news/detail-655972.html

  1. 支持設(shè)置拖拽的最小寬度、最小高度、最大寬度、最大高度
  2. 可以雙擊某一條邊,最大化對(duì)應(yīng)方向的尺寸;再一次雙擊,則會(huì)恢復(fù)到原始大小

sgDragSize源碼

<template>
    <div :class="$options.name" :disabled="disabled" draggable="false">
        <div :class="`resize-handle resize-${a}`" draggable="false" @mousedown.stop="clickResizeHandle(a)"
            @dblclick="dblclickResizeHandle(a, $event)" v-for="(a, i) in sizeIndexs" :key="i"></div>
    </div>
</template>
<script>
export default {
    name: 'sgDragSize',
    data() {
        return {
            tbHeight: 0,
            dragSizeIndex: '',
            originRect: {},
            dblclickOriginRect: {},
            sizeIndexs: [
                'top',
                'right',
                'bottom',
                'left',
                'top-left',
                'top-right',
                'bottom-left',
                'bottom-right',
            ],
        }
    },
    props: [
        "disabled",//屏蔽
        "taskbarHeight",//任務(wù)欄高度
        "minWidth",//拖拽的最小寬度
        "minHeight",//拖拽的最小高度
        "maxWidth",//拖拽的最大寬度
        "maxHeight",//拖拽的最大高度
    ],
    watch: {
        disabled: {
            handler(newValue, oldValue) {
                newValue && this.__removeWindowEvents();
            }, deep: true, immediate: true,
        },
        taskbarHeight: {
            handler(d) {
                this.tbHeight = d || 0;
            }, deep: true, immediate: true,
        },
    },
    destroyed() {
        this.__removeWindowEvents();
    },
    methods: {
        view_innerHeight() {
            return innerHeight - this.tbHeight;
        },
        clickResizeHandle(d) {
            this.dragSizeIndex = d;
            this.mousedown(d);
        },
        dblclickResizeHandle(d, $event) {
            let rect = this.$el.getBoundingClientRect();
            rect.width < innerWidth && rect.height < this.view_innerHeight() && (this.dblclickOriginRect = rect);
            this.dblResize(d, rect, $event);
        },
        __addWindowEvents() {
            this.__removeWindowEvents();
            addEventListener('mousemove', this.mousemove_window);
            addEventListener('mouseup', this.mouseup_window);
        },
        __removeWindowEvents() {
            removeEventListener('mousemove', this.mousemove_window);
            removeEventListener('mouseup', this.mouseup_window);
        },
        mousedown(e) {
            this.originRect = this.$el.getBoundingClientRect();
            this.originRect.bottomRightX = this.originRect.x + this.originRect.width;//右下角坐標(biāo).x
            this.originRect.bottomRightY = this.originRect.y + this.originRect.height;//右下角坐標(biāo).y
            this.$emit('dragStart', e);
            this.__addWindowEvents();
        },
        mousemove_window(e) {
            let { x, y } = e;
            let minWidth = this.minWidth || 50, minHeight = this.minHeight || 50, maxWidth = this.maxWidth || innerWidth, maxHeight = this.maxHeight || innerHeight;
            x < 0 && (x = 0), y < 0 && (y = 0), x > innerWidth && (x = innerWidth), y > this.view_innerHeight() && (y = this.view_innerHeight());
            let style = {};
            switch (this.dragSizeIndex) {
                case 'top-left':
                    style.left = x;
                    style.top = y;
                    style.width = this.originRect.bottomRightX - x;
                    style.width <= minWidth && (style.width = minWidth, style.left = this.originRect.bottomRightX - minWidth);
                    style.height = this.originRect.bottomRightY - y;
                    style.height <= minHeight && (style.height = minHeight, style.top = this.originRect.bottomRightY - minHeight);
                    break;
                case 'top':
                    style.left = this.originRect.x;
                    style.top = y;
                    style.width = this.originRect.width;
                    style.height = this.originRect.bottomRightY - y;
                    style.height <= minHeight && (style.height = minHeight, style.top = this.originRect.bottomRightY - minHeight);
                    break;
                case 'top-right':
                    style.left = this.originRect.x;
                    style.top = y;
                    style.width = x - this.originRect.x;
                    style.width <= minWidth && (style.width = minWidth, style.left = this.originRect.x);
                    style.height = this.originRect.bottomRightY - y;
                    style.height <= minHeight && (style.height = minHeight, style.top = this.originRect.bottomRightY - minHeight);
                    break;
                case 'left':
                    style.left = x;
                    style.top = this.originRect.y;
                    style.width = this.originRect.bottomRightX - x;
                    style.width <= minWidth && (style.width = minWidth, style.left = this.originRect.bottomRightX - minWidth);
                    style.height = this.originRect.height;
                    break;
                case 'right':
                    style.left = this.originRect.x;
                    style.top = this.originRect.y;
                    style.width = x - this.originRect.x;
                    style.width <= minWidth && (style.width = minWidth, style.left = this.originRect.x);
                    style.height = this.originRect.height;
                    break;
                case 'bottom-left':
                    style.left = x;
                    style.top = this.originRect.y;
                    style.width = this.originRect.bottomRightX - x;
                    style.width <= minWidth && (style.width = minWidth, style.left = this.originRect.bottomRightX - minWidth);
                    style.height = y - this.originRect.y;
                    style.height <= minHeight && (style.height = minHeight, style.top = this.originRect.y);
                    break;
                case 'bottom':
                    style.left = this.originRect.x;
                    style.top = this.originRect.y;
                    style.width = this.originRect.width;
                    style.height = y - this.originRect.y;
                    style.height <= minHeight && (style.height = minHeight, style.top = this.originRect.y);
                    break;
                case 'bottom-right':
                    style.left = this.originRect.x;
                    style.top = this.originRect.y;
                    style.width = x - this.originRect.x;
                    style.width <= minWidth && (style.width = minWidth, style.left = this.originRect.x);
                    style.height = y - this.originRect.y;
                    style.height <= minHeight && (style.height = minHeight, style.top = this.originRect.y);
                    break;
                default:
            }
            style.width > maxWidth && (style.width = maxWidth);
            style.height > maxHeight && (style.height = maxHeight);
            Object.keys(style).forEach(k => style[k] = `${style[k]}px`);
            style['transition-property'] = 'width,height';
            style['transition-duration'] = '0,0';
            this.$emit('dragging', { e, style });
        },
        dblResize(d, rect, e) {
            let style = {};
            switch (d) {
                case 'top-left':
                    break;
                case 'top':
                case 'bottom':
                    style.left = this.originRect.x;
                    style.top = rect.height >= this.view_innerHeight() ? this.dblclickOriginRect.y : 0;
                    style.width = this.originRect.width;
                    style.height = rect.height >= this.view_innerHeight() ? this.dblclickOriginRect.height : this.view_innerHeight();
                    break;
                case 'top-right':
                    break;
                case 'left':
                case 'right':
                    style.left = rect.width >= innerWidth ? this.dblclickOriginRect.x : 0;
                    style.top = this.originRect.y;
                    style.width = rect.width >= innerWidth ? this.dblclickOriginRect.width : innerWidth;
                    style.height = this.originRect.height;
                    break;
                case 'bottom-left':
                    break;
                case 'bottom-right':
                    break;
                default:
            }
            Object.keys(style).forEach(k => style[k] = `${style[k]}px`);
            style['transition-property'] = 'width,height';
            style['transition-duration'] = '0.1s,0.1s';
            this.$emit('dragging', { e, style });
        },
        mouseup_window(e) {
            this.$emit('dragEnd', e);
            this.__removeWindowEvents();
        },
    }
};
</script> 
<style lang="scss">
.sgDragSize {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    pointer-events: none;

    .resize-handle {
        position: absolute;
        z-index: 100;
        display: block;
        pointer-events: auto;
    }

    &[disabled] {
        .resize-handle {
            pointer-events: none;
        }
    }

    .resize-top {
        cursor: n-resize;
        top: -3px;
        left: 0px;
        height: 7px;
        width: 100%;
    }

    .resize-right {
        cursor: e-resize;
        right: -3px;
        top: 0px;
        width: 7px;
        height: 100%;
    }

    .resize-bottom {
        cursor: s-resize;
        bottom: -3px;
        left: 0px;
        height: 7px;
        width: 100%;
    }

    .resize-left {
        cursor: w-resize;
        left: -3px;
        top: 0px;
        width: 7px;
        height: 100%;
    }

    .resize-top-right {
        cursor: ne-resize;
        width: 16px;
        height: 16px;
        right: -8px;
        top: -8px;
    }

    .resize-bottom-right {
        cursor: se-resize;
        width: 20px;
        height: 20px;
        right: -8px;
        bottom: -8px;
        background: url('/static/img/desktop/Windows7/sgDragSize/resize_corner.png') no-repeat;
    }

    .resize-bottom-left {
        cursor: sw-resize;
        width: 16px;
        height: 16px;
        left: -8px;
        bottom: -8px;
    }

    .resize-top-left {
        cursor: nw-resize;
        width: 16px;
        height: 16px;
        left: -8px;
        top: -8px;
    }
}
</style>

應(yīng)用

<template>
    <div>
        <div class="box" :style="style">
            <label>最小尺寸:寬度400px,高度200px</label>
            <sgDragSize @dragging="dragging" :minWidth="400" :minHeight="200" />
        </div>
    </div>
</template>
<script>
import sgDragSize from "@/vue/components/admin/sgDragSize";
export default {
    components: {
        sgDragSize,
    },
    data() {
        return {
            style: {
                height: '500px',
                width: '800px',
                left: '100px',
                top: '100px',
            },
        }
    },
    methods: {
        dragging({ style }) {
            this.style = style;
        },
    },
};
</script>
<style lang="scss" scoped>
.box {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #409EFF55;
    box-sizing: border-box;
    border: 1px solid #409EFF;

    label {
        user-select: none;
        color: #409EFF;
    }
}
</style>

到了這里,關(guān)于【sgDragSize】自定義拖拽修改DIV尺寸組件,適用于窗體大小調(diào)整的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue自定義h5video視頻播放器進(jìn)度條組件,可拖拽、跳轉(zhuǎn)、倍速、全屏

    vue自定義h5video視頻播放器進(jìn)度條組件,可拖拽、跳轉(zhuǎn)、倍速、全屏

    一個(gè)進(jìn)度條組件控制多個(gè)視頻的播放、進(jìn)度調(diào)整。視頻可點(diǎn)擊全屏觀看,唯一的進(jìn)度條是某個(gè)指定視頻的視頻信息。 全屏 點(diǎn)擊進(jìn)度條跳轉(zhuǎn) 拖動(dòng)滑塊 在菜鳥教程上有以下幾個(gè)參數(shù)的詳細(xì)解說,這張圖忘記哪里看的了,如有認(rèn)領(lǐng)可評(píng)論我貼鏈接 倍速 // 倍速 handleChangeSpeed(item)

    2024年02月12日
    瀏覽(90)
  • Naive UI 獲取樹tree完整選中樹結(jié)構(gòu)(通用方法,也適用于其他自定義組件)

    截止文章記錄前,Naive UI 并未提供直接獲取,與選中葉子節(jié)點(diǎn)相關(guān)的完整樹結(jié)構(gòu)數(shù)據(jù)方法,記錄一下前端實(shí)現(xiàn)方法。 數(shù)據(jù)準(zhǔn)備: 數(shù)據(jù)準(zhǔn)備:樹結(jié)構(gòu)初始數(shù)據(jù),選中相關(guān)的數(shù)據(jù) ? 實(shí)現(xiàn)步驟,一共四步,如下:? 實(shí)現(xiàn)函數(shù)方法如下:?

    2024年04月13日
    瀏覽(87)
  • 【sgRectSelect】自定義組件:Vue實(shí)現(xiàn)拖拽鼠標(biāo)圈選、劃區(qū)域、框選組件:矩形區(qū)域選中checkbox,并回調(diào)相關(guān)選中、取消選中的操作。

    【sgRectSelect】自定義組件:Vue實(shí)現(xiàn)拖拽鼠標(biāo)圈選、劃區(qū)域、框選組件:矩形區(qū)域選中checkbox,并回調(diào)相關(guān)選中、取消選中的操作。

    邊框線虛線動(dòng)畫效果請(qǐng)參閱 邊框虛線滾動(dòng)動(dòng)畫特效_虛線滾動(dòng)效果_你摯愛的強(qiáng)哥的博客-CSDN博客 【代碼】邊框虛線滾動(dòng)動(dòng)畫特效。_虛線滾動(dòng)效果 https://blog.csdn.net/qq_37860634/article/details/130507289 ? 碰撞檢測(cè)原理請(qǐng)前往? 原生JS完成“一對(duì)一、一對(duì)多”矩形DIV碰撞檢測(cè)、碰撞檢查,

    2024年02月09日
    瀏覽(115)
  • VS+Qt設(shè)置窗口尺寸(二):窗體控件自適應(yīng)窗口布局,自動(dòng)調(diào)整大小

    VS+Qt設(shè)置窗口尺寸(二):窗體控件自適應(yīng)窗口布局,自動(dòng)調(diào)整大小

    VS版本:VS2019 QT版本:Qt5.12.3(msvc2017_64) 為了適配不同尺寸的顯示屏,軟件窗口需要調(diào)整大小,窗口內(nèi)的控件尺寸也要適配窗口的大小。 本例重點(diǎn)講述如何設(shè)置可調(diào)整尺寸的窗口及控件,實(shí)現(xiàn)窗口最大化和尺寸調(diào)節(jié)。 本例使用相對(duì)簡(jiǎn)單的按鍵和文本框來做示例,其他控件均可

    2023年04月23日
    瀏覽(127)
  • JS創(chuàng)建DIV,實(shí)現(xiàn)鼠標(biāo)拖拽效果

    題目:用原生js動(dòng)態(tài)創(chuàng)建一個(gè)div,大小隨意,掛在body上,實(shí)現(xiàn)鼠標(biāo)拖拽效果 需要用到的鼠標(biāo)事件: 1.鼠標(biāo)按下(onmousedown), 2.鼠標(biāo)移動(dòng)(onmousemove) 3.鼠標(biāo)抬起(onmouseup) 第一步:創(chuàng)建容器(每個(gè)頁(yè)面,最大的容器是body對(duì)象,所有dom對(duì)象創(chuàng)建后默認(rèn)都會(huì)放到body) 第二步,

    2024年02月13日
    瀏覽(19)
  • vue實(shí)現(xiàn)在頁(yè)面拖拽放大縮小div并顯示鼠標(biāo)在div的坐標(biāo)

    vue實(shí)現(xiàn)在頁(yè)面拖拽放大縮小div并顯示鼠標(biāo)在div的坐標(biāo)

    實(shí)現(xiàn)在一個(gè)指定區(qū)域拖拽div,并可以放大縮小,同時(shí)顯示鼠標(biāo)在該div里的坐標(biāo),如圖可示 縮小并拖動(dòng) js代碼 css

    2024年02月05日
    瀏覽(228)
  • vue實(shí)現(xiàn)鼠標(biāo)拖拽div左右移動(dòng)的功能

    vue實(shí)現(xiàn)鼠標(biāo)拖拽div左右移動(dòng)的功能

    直接代碼: 這部分區(qū)域可以鼠標(biāo)拖拽左右滾動(dòng)

    2024年02月03日
    瀏覽(95)
  • Qt程序設(shè)計(jì)-無邊框可移動(dòng)可拖拽調(diào)整大小窗體

    本文講解Qt-無邊框可移動(dòng)可拖拽調(diào)整大小窗體。 通過鼠標(biāo)的按下移動(dòng)進(jìn)行窗體的移動(dòng),拖拽調(diào)整窗體大小。 實(shí)現(xiàn)過程如下: 創(chuàng)建QWidget窗體,添加一個(gè)按鈕控制窗體的關(guān)閉。

    2024年02月19日
    瀏覽(42)
  • vue2和vue3拖拽移動(dòng)div

    直接上代碼,代碼可以直接運(yùn)行, vue2拖拽移動(dòng)div: vue3拖拽移動(dòng)div: 設(shè)置div居中后,發(fā)現(xiàn)一開始拖拽時(shí),div會(huì)跑到最左邊,vue3優(yōu)化代碼如下:

    2024年02月07日
    瀏覽(21)
  • Vue3中div自由拖拽寬度和高度。

    Vue3中div自由拖拽寬度和高度。

    Vue3中我們會(huì)遇到自由拖拽寬度和高度的頁(yè)面需求,查看很多方法都無法滿足當(dāng)前需求。下面是我們Vue3版本的代碼,非常簡(jiǎn)單主要構(gòu)想說粗發(fā)拖拽方法,把所需要的div的高寬進(jìn)行拖拽位置進(jìn)行監(jiān)聽來加減自身div的px值。直接復(fù)制粘貼就可以實(shí)現(xiàn)效果。根據(jù)自己需求更改即可投入

    2024年02月09日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包