JavaScript Placing interactive box on top of the canvas on mouseleave

I'm trying to make a box follow the cursor on mousemove. However, it should stop following the mouse if

  1. the user clicks the box
  2. the user's mouse leaves the surrounding div

Here's what the current setup looks like:

box that follows cursor on mousemove

$(function() {
  $(document).mousemove(function(e) {

    // assign the co-ords as vars so 
    var vert = e.pageY;
    var horz = e.pageX;

    // get co -ords for the center of the box
    centx = Math.ceil($('div').width() / 2);
    centy = Math.ceil($('div').height() / 2);

    // checking to see if the cursor is outside the boudries of the box and stoping the circle moving past them
    if (e.pageY + 53 > Math.ceil($('div').height())) var vert = Math.ceil($('div').height() - 47);
    if (e.pageY - 53 < 0) vert = 53;
    if (e.pageX + 53 > Math.ceil($('div').width())) var horz = Math.ceil($('div').width() - 47);
    if (e.pageX - 53 < 0) horz = 53;

    // work out the distance between the cursor and the center of box
    disx = horz - centx;
    disy = vert - centy;

    // work out the scale of the shadow
    sx = -disx * 0.1;
    sy = -disy * 0.1;

    // work out the shadow blur
    b = (Math.abs(sx) + Math.abs(sy)) * 0.5;

    //apply the css
    $('p').css({
      'top': vert - 53,
      'left': horz - 53,
      '-webkit-box-shadow': '#a0a0a0 ' + sx + 'px ' + sy + 'px ' + b + 'px, inset ' + sx + 'px ' + sy + 'px ' + b + 'px #e3e3e3'
    });
  });
});
body {
  padding: 0px;
}
div {
  position: relative;
  width: 400px;
  height: 400px;
  background-color: #f0f0f0;
}
p {
  background-color: orange;
  height: 100px;
  width: 100px;
  position: absolute;
  top: 100px;
  left: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div>
  <p>set the location</p>
</div>
Answer:1

What is the difference between the following two functions as far as promises are concerned? var service = { someFunction: function() { return $http.get('url').then(function (response) { ...

What is the difference between the following two functions as far as promises are concerned? var service = { someFunction: function() { return $http.get('url').then(function (response) { ...

  1. javascript promises function
  2. javascript promise function example
  3. javascript promise function return value
  4. javascript promise function parameters
  5. javascript promise function return
  6. javascript promise function arguments
  7. javascript promise function call
  8. javascript promise function then
  9. javascript promise function variable
  10. js promises function
  11. javascript promise function chain
  12. javascript promise function name
  13. javascript promise function implementation
  14. js promise function example
  15. js promise function call
  16. js promise function then
  17. javascript promises callback function
  18. javascript create promise function
  19. javascript promise arrow function
  20. javascript promise recursive function

Edit I figured out that it is actually fading out, it just removes the background image before it starts the fade so I can't see it...duh. I just removed the .css('background','') so it fades out now....

Edit I figured out that it is actually fading out, it just removes the background image before it starts the fade so I can't see it...duh. I just removed the .css('background','') so it fades out now....

  1. trouble transitioning out of swaddle
  2. trouble transitioning from one activity to another
  3. trouble transitioning to sippy cup
  4. trouble transitioning
  5. trouble transitioning from bassinet to crib
  6. trouble transitioning from breast to bottle
  7. trouble transitioning from bottle to sippy cup
  8. trouble transitioning to toddler bed
  9. trouble transitioning to kindergarten
  10. trouble transitioning to adulthood
  11. trouble transitioning from crib to bed
  12. trouble transitioning baby to crib
  13. trouble transitioning from swaddle
  14. trouble transitioning to table food

Can someone give me an example of how to make an ajax call by JQuery within an HTML page to a Java Servlet (please post the full code of the html page, the call and the Servlet Class). I want to do ...

Can someone give me an example of how to make an ajax call by JQuery within an HTML page to a Java Servlet (please post the full code of the html page, the call and the Servlet Class). I want to do ...

  1. jquery ajax java servlet example
  2. jquery post java servlet
  3. jquery datatables java servlet example
  4. jquery call java servlet
  5. jquery to java servlet
  6. jquery ajax post java servlet
  7. jquery file upload java servlet example
  8. jquery file upload java servlet
  9. jquery validate remote java servlet
  10. jquery ajax jsp servlet java example
  11. jquery ajax request to java servlet
  12. jquery ajax java servlet
  13. jquery ajax json java servlet example
  14. jquery java servlet example

In this Post How to move to prev/next element of an array its telling how to move prev/next a array ellement. But i want the same concept for Prev/Next Array Element Key. Ex: var arr = new Array(); ...

In this Post How to move to prev/next element of an array its telling how to move prev/next a array ellement. But i want the same concept for Prev/Next Array Element Key. Ex: var arr = new Array(); ...