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

vue實現(xiàn)拖拽小圖標(biāo)

 更新時間:2022年03月04日 17:42:39   作者:祎祎呀  
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)拖拽小圖標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

如何給vue項目里面寫拖拽懸浮小圖標(biāo)呢,供大家參考,具體內(nèi)容如下

首先

1、html文件 一定要給父盒子一個ID

<div
? ? ? class="xuanfu"
? ? ? id="moveDiv"
? ? ? @mousedown="down()"
? ? ? @touchstart="down()"
? ? ? @mousemove.prevent.stop="move()"
? ? ? @touchmove.prevent.stop="move()"
? ? ? @mouseup="end()"
? ? ? @touchend="end()"
? ? >
? ? ? <img class="img-kf" src="../../assets/images/csVip/kf.png" />
</div>

2、在data里面設(shè)置

position: { x: 0, y: 0 },
? ? ? nx: "",
? ? ? ny: "",
? ? ? dx: "",
? ? ? dy: "",
? ? ? xPum: "",
? ? ? yPum: "",

3、在方法里面寫拖拽方法

//移動端拖拽事件
? ? down() {
? ? ? this.flags = true;
? ? ? let touch;
? ? ? if (event.touches) {
? ? ? ? touch = event.touches[0];
? ? ? } else {
? ? ? ? touch = event;
? ? ? }
? ? ? this.position.x = touch.clientX;
? ? ? this.position.y = touch.clientY;
? ? ? this.dx = moveDiv.offsetLeft;
? ? ? this.dy = moveDiv.offsetTop;
? ? },
? ? move() {
? ? ? if (this.flags) {
? ? ? ? let 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;
? ? ? ? //添加限制:只允許在屏幕內(nèi)拖動

? ? ? ? //屏幕寬度減去懸浮框?qū)捀?
? ? ? ? const maxWidth = document.body.clientWidth - 54;
? ? ? ? const maxHeight = document.body.clientHeight - 54;
? ? ? ? if (this.xPum < 0) {
? ? ? ? ? //屏幕x限制
? ? ? ? ? this.xPum = 0;
? ? ? ? } else if (this.xPum > maxWidth) {
? ? ? ? ? this.xPum = maxWidth;
? ? ? ? }
? ? ? ? if (this.yPum < 0) {
? ? ? ? ? //屏幕y限制
? ? ? ? ? this.yPum = 0;
? ? ? ? } else if (this.yPum > maxHeight) {
? ? ? ? ? this.yPum = maxHeight;
? ? ? ? }
? ? ? ? moveDiv.style.left = this.xPum + "px";
? ? ? ? moveDiv.style.top = this.yPum + "px";
? ? ? ? //阻止頁面的滑動默認(rèn)事件
? ? ? ? document.addEventListener(
? ? ? ? ? "touchmove",
? ? ? ? ? function () {
? ? ? ? ? ? // 1.2 如果碰到滑動問題,請注意是否獲取到 touchmove
? ? ? ? ? ? // event.preventDefault(); //jq 阻止冒泡事件
? ? ? ? ? ? event.stopPropagation(); // 如果沒有引入jq 就用 stopPropagation()
? ? ? ? ? },
? ? ? ? ? false
? ? ? ? );
? ? ? }
? ? },
? ? //鼠標(biāo)釋放時候的函數(shù)
? ? end() {
? ? ? this.flags = false;
? ? },

4、css樣式

.xuanfu {
? ? width: 1.7rem;
? ? height: 1.7rem;
? ? border-radius: 50%;
? ? // background: rgb(213, 91, 91);
? ? position: fixed;

? ? bottom: 4rem;
? ? right: 0.4rem;
? ? z-index: 9999999999;
? ? text-align: center;

? ? .img-kf {
? ? ? width: 1.7rem;
? ? ? height: 1.7rem;
? ? }
? }

到這里,我們的懸浮小圖標(biāo)就做完了。

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

相關(guān)文章

  • vue 如何將二維數(shù)組轉(zhuǎn)化為一維數(shù)組

    vue 如何將二維數(shù)組轉(zhuǎn)化為一維數(shù)組

    這篇文章主要介紹了vue 如何將二維數(shù)組轉(zhuǎn)化為一維數(shù)組,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue pages 多入口項目 + chainWebpack 全局引用縮寫說明

    vue pages 多入口項目 + chainWebpack 全局引用縮寫說明

    這篇文章主要介紹了vue pages 多入口項目 + chainWebpack 全局引用縮寫說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue 中幾種傳值方法(3種)

    vue 中幾種傳值方法(3種)

    這篇文章主要介紹了vue 中幾種傳值方法(3種),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • iview同時驗證多個表單問題總結(jié)

    iview同時驗證多個表單問題總結(jié)

    這篇文章主要介紹了iview同時驗證多個表單問題總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • vue結(jié)合Axios+v-for列表循環(huán)實現(xiàn)網(wǎng)易健康頁面(實例代碼)

    vue結(jié)合Axios+v-for列表循環(huán)實現(xiàn)網(wǎng)易健康頁面(實例代碼)

    這篇文章主要介紹了vue結(jié)合Axios+v-for列表循環(huán)實現(xiàn)網(wǎng)易健康頁面,在項目下安裝axios,通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • vuecli中chainWebpack的常用操作舉例

    vuecli中chainWebpack的常用操作舉例

    在項目開發(fā)中我們難免碰到需要對webpack配置更改的情況,下面這篇文章主要給大家介紹了關(guān)于vuecli中chainWebpack的常用操作舉例,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • 詳解polyfills如何按需加載及場景示例詳解

    詳解polyfills如何按需加載及場景示例詳解

    這篇文章主要為大家介紹了詳解polyfills如何按需加載及場景示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • 原生javascript中檢查對象是否為空示例實現(xiàn)

    原生javascript中檢查對象是否為空示例實現(xiàn)

    這篇文章主要為大家介紹了原生javascript中檢查對象是否為空示例實現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2021-11-11
  • Vue自定義指令directive的使用方法分享

    Vue自定義指令directive的使用方法分享

    這篇文章主要為大家詳細(xì)介紹了Vue中自定義指令directive的使用方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-04-04
  • vue3使用particles插件實現(xiàn)粒子背景的方法詳解

    vue3使用particles插件實現(xiàn)粒子背景的方法詳解

    這篇文章主要為大家詳細(xì)介紹了vue3使用particles插件實現(xiàn)粒子背景的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03

最新評論