I have this js:
var clicking = false;
$('.drag-me').mousedown(function(){
clicking = true;
$('.status').text('mousedown');
});
$(document).mouseup(function(){
clicking = false;
$('.status').text('mouseup');
$('.status').text('click released, no more move event');
})
$('.drag-me').mousemove(function(e){
if(clicking == false) return;
// Mouse click + moving logic here
$('.status').text('mouse moving');
var change=lastx-e.pageX;
var lastx= e.pageX;
$(this).css('width',$(this).width+change+'px')
$('.cords').html('x:'+e.pageX+' y: '+e.pageY);
});
And html:
<div class="drag-me">Drag me</div>
<div class="status">Nothing</div>
<div class="cords">Cords</div>
CSS:
.drag-me {
background:blue;
width:100px;
height:30px;
}
问题:
现在当我在.drag-me
内移动鼠标时,我希望它可以增加/减少其大小。
但它并没有发生这种情况。为什么?
我错在哪里了?