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

120
Views
Is it possible to fire mouse events without mouse moves in safari?

I'm trying to put mouse enter/mouse-leave events on moving elements. There is a problem in handling the hover event with CSS, so I'm trying to process it with JS. This works fine in chrome but not working in safari. How to make mouseenter/mouseleave work properly when the mouse is stopped?

CSS

.big-box {
    position: relative;
    width: 500px;
    height: 100px;
    background: #ee9;
}
.hit-box {
    position: absolute;
    top: 0;
    left: 0;
    width: 100px;
    height: 100px;
    background: #e99;
}

HTML

<div class="big-box">
    <div class="hit-box">hit-box</div>
</div>

JavaScript

const hitbox = document.querySelector('.hit-box');
var position = 5;
hitbox.style.left = 0;

hitbox.addEventListener('mouseenter', function() {
    console.log('enter');
});
hitbox.addEventListener('mouseleave', function() {
    console.log('leave');
});

setInterval(function() {
    if(parseInt(hitbox.style.left) + position > 400) {
        position = -5;
    } else if(parseInt(hitbox.style.left) + position < 0) {
        position= 5;
    }
    hitbox.style.left = parseInt(hitbox.style.left) + position + 'px';
},20)
about 4 years ago · Juan Pablo Isaza
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!