鼠标拖拽,给图片打点,显示坐标

核心代码:

function move(){
var x,y;
$('.point').mousedown(function (){
var _num = $(this).text();
$(this).css('z-index','10');
var _w=parseInt($(this).css("width"))/2;
var _h=parseInt($(this).css("height"))/2;
var marginTop = $('.img-box').offset().top;
var marginLeft = $('.img-box').offset().left;
$('.point-list .num'+_num+'').addClass('active').siblings().removeClass('active');
$(this).mousemove(function (event){
var ox=event.clientX-marginLeft;
var oy=event.clientY-marginTop;
var t=oy-_h;
var l=ox-_w;
var w=$('.img-box').width()-$('.point').width();
var h=$('.img-box').height()-$('.point').height();
if(t<0){
t=0;
}
else if(t>h){
t=h;
}
if(l<0){
l=0;
}
else if(l>w){
l=w;
}
x=parseInt(l+parseInt($(this).css('width'))/2);
y=parseInt(t+parseInt($(this).css('height')));
$(this).css({top:t,left:l});

$('.point-list .num'+_num+' .x-num').html(x);
$('.point-list .num'+_num+' .y-num').html(y);
})
});
$('.point').mouseup(function (){
$(this).unbind("mousemove");
$(this).css('z-index','1');
});
}

转载于:https://www.cnblogs.com/duanyue/p/7065095.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值