0

I'm changing the width of my div based upon mouse movement.

This is called when mouse moves:

p.resize = function(e) {

    var w += e.clientX
    myDiv.css({width:w});

};

The problem is the width increases by a lot each time, I need to find out how much the mouse has moved relative to the last time it moved, so I can then increase my div by the amount.

I'm not sure how to implement this, could someone help?

panthro
  • 22,779
  • 66
  • 183
  • 324
  • capture the mouse position at regular intervals (settimeout or some such) and update then? related : http://stackoverflow.com/questions/7790725/javascript-track-mouse-position – EvilEpidemic May 19 '14 at 10:44
  • what if you just remove the `+` ? – Spokey May 19 '14 at 10:54

1 Answers1

0

Script

$( "div" ).mousemove(function( event ) { 
     var w = (event.pageX < 250) ? event.pageX :250;
     var h = (event.pageY < 250) ? event.pageY :250;
     $(this).css({"width":w,"height":h});    
 });

http://fiddle.jshell.net/UNJ9Z/1/

vintot
  • 260
  • 1
  • 2
  • 10