div旋转 vue_Vue实现按钮旋转和移动位置的实例代码_蜡烛_前端开发者
发布日期:2021-06-24 15:56:45 浏览次数:2 分类:技术文章

本文共 2273 字,大约阅读时间需要 7 分钟。

1.静态效果图

Chrom移动端浏览模式下可拖动按钮处于任意位置,并且点击可旋转按钮

2.代码

export default {

name: 'App',

data(){

return{

/*--------图标样式变量--------------*/

iconrotate:45,//旋转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 触发

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 触发

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(){//图标动态样式

let arr = new Array();

arr.push('transform:');//注意:先移动后旋转,实现原地旋转;先旋转后移动,位置按照旋转后的新坐标系确定

arr.push('translateX('+this.icontranslateX+'px) ');

arr.push('translateY('+this.icontranslateY+'px) ');

arr.push('rotate('+this.iconrotate+'deg) ');

return arr.join("");

}

}

}

#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;

}

总结

以上所述是小编给大家介绍的开发者网站的支持!

转载地址:https://blog.csdn.net/weixin_33682804/article/details/112816652 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:switchresx卸载_SwitchResX
下一篇:如何区分用户_通信中的多址技术:基站如何区分不同用户,时分与频分多址技术...

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月24日 19时31分25秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章