Reputation: 21
I have this on-mouse-enter trigger code (JavaScript to listen for mouse enters and CSS for transitions) and lately, it's been acting funny in Chrome; tested on v 44.0.2403.157m without any error in the console. By acting funny, I mean that fade in-out effect sometimes is skipping.
var shown = true;
var parent = document.querySelector('.parent');
var child = document.querySelector('.child');
parent.addEventListener('mouseenter', function(){
child.style.opacity = shown ? 0 : 1;
shown = !shown;
});
* {
margin: 0;
padding: 0;
}
.parent {
width: 100%;
margin: 10px auto;
position: relative;
}
.child {
position: absolute;
top: 0;
width: 100%;
height: 100%;
display: block;
overflow: hidden;
transition: opacity 0.5s linear;
}
p {
padding: 1em;
}
<div class="parent">
<img src="http://www.fundraising123.org/files/u16/bigstock-Test-word-on-white-keyboard-27134336.jpg" alt="" width="500px" height="auto" />
<div class="child">
<img src="http://maui.hawaii.edu/tlc/wp-content/uploads/sites/53/2013/11/testing.jpg" alt="" width="500px" height="auto" />
</div>
</div>
The code should work like we have in this example. I would greatly appreciate to have your code alternatives and thoughts. Thanks
Upvotes: 4
Views: 172