ionic客服拖拽

经公司要求要写一个客服图标显示在app的屏幕上,用户可以随意拖到这个图标的位置,后面就用ionic的手势事件写了一个拖拽的功能,下面是代码
//客服拖拽
var ox,oy,
    totalHeight=window.screen.availHeight,//获取屏幕的高度
    totalWidth=window.screen.availWidth;//获取屏幕的宽度

//按下
$rootScope.onTouch = function($event){
    ox = $event.target.offsetLeft;
    oy = $event.target.offsetTop;
};
//拖拽
$rootScope.onDrag = function($event){
    var el = $event.target,
        dx = $event.gesture.deltaX,
        dy = $event.gesture.deltaY;
    el.style.left = ox + dx + "px";
    el.style.top = oy + dy + "px";
};
//松开
$rootScope.onRelease = function($event) {
    var el = $event.target;
    if (el.offsetTop < el.offsetHeight) {
        el.style.top = '10px';
    } else if (el.offsetTop > totalHeight - el.offsetHeight) {
        el.style.top = totalHeight - el.offsetHeight - 10 + "px";
    }
    if (el.offsetLeft < el.offsetHeight) {
        el.style.left = "10px";
    } else if (el.offsetLeft > totalWidth - el.offsetWidth) {
        el.style.left = totalWidth - el.offsetWidth - 10 + "px";
    }
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值