国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue實現(xiàn)按鈕旋轉(zhuǎn)和移動位置的實例代碼

2019-11-19 13:18:06
字體:
供稿:網(wǎng)友

1.靜態(tài)效果圖

Chrom移動端瀏覽模式下可拖動按鈕處于任意位置,并且點擊可旋轉(zhuǎn)按鈕

2.代碼

<template> <div id="app">  <div class="icon-add-50" :style="iconstyle" @click='click' @touchmove='touchmove' @touchstart='touchstart(this,$event)' @touchend='touchend'></div> </div></template><script>export default { name: 'App', data(){  return{   /*--------圖標樣式變量--------------*/   iconrotate:45,//旋轉(zhuǎn)deg   icontranslateX:100,//沿x軸位移px   icontranslateY:100,//沿y軸位移px   /*--------拖動計算變量------------*/   mouseX:0,   mouseY:0,   objX:0,   objY:0,   isDown:false  } }, methods:{  click:function(){//圖標點擊事件   if (this.iconrotate==0) {     this.iconrotate=315;   }else {    this.iconrotate=0;   }  },  touchstart:function(obj,e){//finger touch 觸發(fā)   this.objX = this.icontranslateX;   this.objY = this.icontranslateY;   this.mouseX = e.touches[0].clientX;   this.mouseY = e.touches[0].clientY;   this.isDowm = true;  },  touchmove:function(e){//finger move 觸發(fā)   let x = e.touches[0].clientX;   let y = e.touches[0].clientY;   if (this.isDowm) {     this.icontranslateX = parseInt(x) - parseInt(this.mouseX) + parseInt(this.objX);     this.icontranslateY = parseInt(y) - parseInt(this.mouseY) + parseInt(this.objY);   }  },  touchend:function(e){//finger from touch to notouch   if (this.isDowm) {     let x = e.touches[0].clientX;     let y = e.touches[0].clientY;     this.icontranslateX = parseInt(x) - parseInt(this.mouseX)+ parseInt(this.objX);     this.icontranslateY = parseInt(y) - parseInt(this.mouseY)+ parseInt(this.objY);     this.isDowm=false;   }  } }, computed:{  iconstyle:function(){//圖標動態(tài)樣式   let arr = new Array();   arr.push('transform:');//注意:先移動后旋轉(zhuǎn),實現(xiàn)原地旋轉(zhuǎn);先旋轉(zhuǎn)后移動,位置按照旋轉(zhuǎn)后的新坐標系確定   arr.push('translateX('+this.icontranslateX+'px) ');   arr.push('translateY('+this.icontranslateY+'px) ');   arr.push('rotate('+this.iconrotate+'deg) ');   return arr.join("");  } }}</script><style>#app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px;} /*加號*/.icon-add-50{  position: relative;  box-sizing: border-box;  width: 50px;  height: 50px;  border: 2px solid gray;  border-radius: 50%;  box-shadow:darkgrey 0px 0px 2px 2px;  background-color: CornflowerBlue;}.icon-add-50:before{  content: '';  position: absolute;  width: 30px;  height: 2px;  left: 50%;  top: 50%;  margin-left: -15px;  margin-top: -1px;  background-color: white;}.icon-add-50:after{  content: '';  position: absolute;  width: 2px;  height: 30px;  left: 50%;  top: 50%;  margin-left: -1px;  margin-top: -15px;  background-color: white;}</style>

總結(jié)

以上所述是小編給大家介紹的Vue實現(xiàn)按鈕旋轉(zhuǎn)和移動位置的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 错那县| 乃东县| 舞钢市| 将乐县| 晋江市| 康马县| 铜梁县| 通渭县| 资源县| 大悟县| 甘洛县| 象山县| 临高县| 成安县| 建阳市| 大渡口区| 哈尔滨市| 盐亭县| 房山区| 开原市| 牙克石市| 泽州县| 新晃| 百色市| 石城县| 黎城县| 曲靖市| 岱山县| 北川| 老河口市| 海林市| 平塘县| 逊克县| 丰顺县| 澎湖县| 罗山县| 高州市| 马尔康县| 武功县| 都兰县| 马边|