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

vue項目實現(xiàn)按鈕可隨意移動

 更新時間:2022年03月30日 08:51:15   作者:帥_帥  
這篇文章主要為大家詳細介紹了vue項目實現(xiàn)按鈕可隨意移動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

vue項目中實現(xiàn)按鈕可隨意移動,供大家參考,具體內(nèi)容如下

組件代碼如下:

在項目中引入該組件即可

<template>
? <div v-show="hide" class="move-button" ref="moveBtn"
? ? ? ?@mousedown="btnDown"
? ? ? ?@touchstart="btnDown"
? ? ? ?@mousemove="btnMove"
? ? ? ?@touchmove="btnMove"
? ? ? ?@mouseup="btnEnd"
? ? ? ?@touchend="btnEnd"
? ? ? ?@touchcancel="btnEnd">
? ? <div class="button-mainbg">
? ? </div>
?? ?</div>
</template>

<script>
export default {
? ? name: 'MoveButton',
? ? data() {
? ? ? ? return {
? ? ? ? ? ? hide: true,
? ? ? ? ? ? img: require('@/assets/img/moveButton.png'),
? ? ? ? ? ? flags: false,
? ? ? ? ? ? position: {
? ? ? ? ? ? ? ? x: 0,
? ? ? ? ? ? ? ? y: 0
? ? ? ? ? ? },
? ? ? ? ? ? nx: '',
? ? ? ? ? ? ny: '',
? ? ? ? ? ? dx: '',
? ? ? ? ? ? dy: '',
? ? ? ? ? ? xPum: '',
? ? ? ? ? ? yPum: '',
? ? ? ? ? ? isShow: false,
? ? ? ? ? ? moveBtn: {},
? ? ? ? ? ? timer: null,
? ? ? ? ? ? currentTop:0
? ? ? ? }
? ? },
? ? mounted() {
? ? ? ? this.moveBtn = this.$refs.moveBtn;
? ? ? ? window.addEventListener('scroll', this.hideButton);
? ? },
? ? beforeDestroy() {
? ? ? ? window.addEventListener('scroll', this.hideButton);
? ? },
? ? methods: {
? ? ? ? hideButton() {
? ? ? ? ? ? this.timer&&clearTimeout(this.timer);
? ? ? ? ? ? this.timer = setTimeout(()=>{
? ? ? ? ? ? ?this.handleScrollEnd();
? ? ? ? ? ? },300);
? ? ? ? ? ? this.currentTop = document.documentElement.scrollTop || document.body.scrollTop;
? ? ? ? ? ? this.hide = false;
? ? ? ? },
? ? ? ? handleScrollEnd(){
? ? ? ? ? ? let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
? ? ? ? ? ? if(scrollTop === this.currentTop){
? ? ? ? ? ? this.hide = true;
? ? ? ? ? ? clearTimeout(this.timer);
? ? ? ? ? ? }
? ? ? ? },

? ? ? ? // 實現(xiàn)移動端拖拽
? ? ? btnDown() {
? ? ? ? ? ? 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 = this.moveBtn.offsetLeft;
? ? ? ? ? ? this.dy = this.moveBtn.offsetTop;
? ? ? ? },
? ? ? btnMove() {
? ? ? ? ? ? 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;
? ? ? ? ? ? ? ? let clientWidth = document.documentElement.clientWidth;
? ? ? ? ? ? ? let clientHeight = document.documentElement.clientHeight;
? ? ? ? ? ? ? ? if (this.xPum > 0 && this.xPum < (clientWidth - this.moveBtn.offsetWidth)) {
? ? ? ? ? ? ? ? ? ? this.moveBtn.style.left = this.xPum + "px";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (this.yPum > 0 && this.yPum < (clientHeight - this.moveBtn.offsetHeight)) {
? ? ? ? ? ? ? ? ? ? this.moveBtn.style.top = this.yPum + "px";
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? //阻止頁面的滑動默認事件
? ? ? ? ? ? ? ? document.addEventListener("touchmove", this.handler, {
? ? ? ? ? ? ? ? ? ? passive: false
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? //鼠標釋放時候的函數(shù)
? ? ? ? btnEnd() {
? ? ? ? ? ? this.flags = false;
? ? ? ? ? ? document.addEventListener('touchmove', this.handler, {
? ? ? ? ? ? ? ? passive: false
? ? ? ? ? ? });
? ? ? ? },
? ? ? ? handler(e) {
? ? ? ? ? ? if(this.flags){
? ? ? ? ? ? ? ? event.preventDefault();
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? return true
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
</script>

<style lang="stylus" scoped>
.move-button {

? ? border-radius:50%;
? ? width: 50px;
? ? height: 50px;
? ? position: fixed;
? ? z-index: 10;

? color: #FFF;

? .button-mainbg{
? ? position: relative;
? ? width:50px;
? ? height:50px;
? ? border-radius:50%;
? ? background: url("../../assets/img/moveButton.png") no-repeat;
? ? background-size: 50px 50px;
? }


}
</style>

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

相關(guān)文章

  • 詳解Vue基于vue-quill-editor富文本編輯器使用心得

    詳解Vue基于vue-quill-editor富文本編輯器使用心得

    這篇文章主要介紹了Vue基于vue-quill-editor富文本編輯器使用心得,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • vue實現(xiàn)拖拽滑動分割面板

    vue實現(xiàn)拖拽滑動分割面板

    這篇文章主要為大家詳細介紹了vue實現(xiàn)拖拽滑動分割面板,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 關(guān)于Element?table組件滾動條不顯示的踩坑記錄

    關(guān)于Element?table組件滾動條不顯示的踩坑記錄

    這篇文章主要介紹了關(guān)于Element?table組件滾動條不顯示的踩坑記錄,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue+Element UI實現(xiàn)概要小彈窗的全過程

    Vue+Element UI實現(xiàn)概要小彈窗的全過程

    彈窗效果是我們?nèi)粘i_發(fā)中經(jīng)常遇到的一個功能,下面這篇文章主要給大家介紹了關(guān)于Vue+Element UI實現(xiàn)概要小彈窗的相關(guān)資料,需要的朋友可以參考下
    2021-05-05
  • Vue.js中的computed功能設(shè)計

    Vue.js中的computed功能設(shè)計

    computed作為計算屬性其作用是描述響應式數(shù)據(jù)的復雜邏輯計算,當所依賴的響應式數(shù)據(jù)發(fā)生改變時計算屬性會重新計算,更新邏輯計算的結(jié)果,這篇文章主要介紹了Vue.js中的computed的功能設(shè)計,需要的朋友可以參考下
    2023-06-06
  • 一文帶你了解什么是Vue?Vapor

    一文帶你了解什么是Vue?Vapor

    隨著Svelte和SolidJS的流行,無虛擬DOM模式逐漸開始火了起來,Vue?Vapor就是一個無虛擬DOM模式版本的vue,下面就跟隨小編一起來深入了解一下Vue?Vapor吧
    2024-11-11
  • VUE開發(fā)分布式醫(yī)療掛號系統(tǒng)后臺管理頁面步驟

    VUE開發(fā)分布式醫(yī)療掛號系統(tǒng)后臺管理頁面步驟

    本文從整體上介紹Vue框架的開發(fā)流程,結(jié)合具體的案例,使用Vue框架調(diào)用具體的后端接口,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-04-04
  • Vue+Axios實現(xiàn)文件上傳自定義進度條

    Vue+Axios實現(xiàn)文件上傳自定義進度條

    這篇文章主要為大家詳細介紹了Vue+Axios實現(xiàn)文件上傳自定義進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • vue實現(xiàn)同時設(shè)置多個倒計時

    vue實現(xiàn)同時設(shè)置多個倒計時

    這篇文章主要為大家詳細介紹了vue實現(xiàn)同時設(shè)置多個倒計時,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Vue項目中如何引入本地第三方JS庫

    Vue項目中如何引入本地第三方JS庫

    vue中常遇到第三方j(luò)s,這篇文章主要給大家介紹了關(guān)于Vue項目中如何引入本地第三方JS庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-06-06

最新評論

万盛区| 稻城县| 仁化县| 兴国县| 上栗县| 东兴市| 宁阳县| 大渡口区| 尚义县| 南城县| 浙江省| 黑龙江省| 白山市| 龙岩市| 陈巴尔虎旗| 上犹县| 鄂托克前旗| 五峰| 绥阳县| 奇台县| 承德市| 龙州县| 璧山县| 剑河县| 荔浦县| 徐汇区| 敖汉旗| 泗阳县| 白银市| 新晃| 江永县| 汝城县| 通渭县| 延安市| 田林县| 读书| 龙井市| 蒲江县| 嘉祥县| 福泉市| 宁城县|