Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
jQuery function based on area of an image

I would like to feed a cat with burgers. If you grab a burger and bring it to the cat's mouth, the burger should disappear.

Currently it looks like that:

$(function() {
  $(".burger").draggable();
});

$(".burger").on("click touchend", function() {
  $(this).css("display", "none");
});
* {
  font-size: 50px;
}

img {
  width: 200px;
}

.burger {
  cursor: grab;
  display: inline-block;
}
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

<img src="https://upload.wikimedia.org/wikipedia/commons/f/f8/Manul_kitten.jpg">

<div class="burger">๐Ÿ”</div>
<div class="burger">๐Ÿ”</div>
<div class="burger">๐Ÿ”</div>

How can I let it work that the burger only disappears close to the cat's mouth?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

create hidden element above the image and set droppable.

$(function() {
  $(".burger").draggable({ revert: "invalid" });
});
$(".droppable").droppable({
  drop: function(event, ui) {
     ui.draggable.remove();
  }
});
* {
  font-size: 50px;
}

img {
  width: 200px;
}

.burger {
  cursor: grab;
  display: inline-block;
}

.wrap {
  position: relative
}

.droppable {
  position: absolute;
  top: 34px;
  left: 125px;
  display: block;
  width: 40px;
  height: 40px;
  border: 2px solid yellow; /*remove to hide*/
}
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

<div class="wrap">
  <div class="droppable"></div>
  <img src="https://upload.wikimedia.org/wikipedia/commons/f/f8/Manul_kitten.jpg">
</div>


<div class="burger">๐Ÿ”</div>
<div class="burger">๐Ÿ”</div>
<div class="burger">๐Ÿ”</div>

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!