jQuery Event How to - Resize element when mouse moves








Question

We would like to know how to resize element when mouse moves.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  w ww  .  j ava 2 s .c  o  m-->
    $(this).mousemove(function(e) {
        $('.style1').width(e.pageX);
    });
});
</script>
</head>
<body>
  <div style="background-color: red;" class="style1">test</div>
</body>
</html>

The code above is rendered as follows: