Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery resize on mousemove not working

Tags:

jquery

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

demo

QUESTION: Now when i move the mouse inside .drag-me i want it to increase/decrease its size. But it doesnt happens so. Why ? Where have i been going wrong ?

like image 229
kritya Avatar asked Feb 21 '26 09:02

kritya


1 Answers

I changed:

$(this).css('width',$(this).width+change+'px')  

to

$(this).width(e.pageX);

And seemed to get the desired result.

http://jsfiddle.net/kmEGF/26/

like image 172
Blazemonger Avatar answered Feb 24 '26 20:02

Blazemonger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!