I have two Divs (CSS is TailwindCss
)
$(document).on("mouseover", "#imagebox", function() { $("#PictureHoverPanel").removeClass("invisible"); }) $(document).on("mouseout", "#imagebox", function() { $("#PictureHoverPanel").addClass("invisible"); })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.3/tailwind.min.css" integrity="sha512-wl80ucxCRpLkfaCnbM88y4AxnutbGk327762eM9E/rRTvY/ZGAHWMZrYUq66VQBYMIYDFpDdJAOGSLyIPHZ2IQ==" crossorigin="anonymous" /> <div id="PictureHoverPanel" class="invisible absolute flex flex-col justify-center rounded-xl bg-gray-600 opacity-70"> <div class="flex justify-center"> <a class="bg-gray-800 px-2 py-1 text-white border border-red-800 font-semibold cursor-pointer">Remove</a> </div> </div> <img id="imagebox" class="w-48 h-48 rounded-xl md:w-64 md:h-64" src="https://picsum.photos/seed/1/100">
The problem is as I enter #imagebox
every mouse move triggers the mouseout
event resulting in a really quick blink. How can I make sure that the invisible
class will not be added unless the cursor is fully out of imagebox
$(document).on("mouseover", "#imagebox", function() { $("#PictureHoverPanel").removeClass("invisible"); }) $(document).on("mouseout", "#imagebox", function() { $("#PictureHoverPanel").addClass("invisible"); })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.3/tailwind.min.css" integrity="sha512-wl80ucxCRpLkfaCnbM88y4AxnutbGk327762eM9E/rRTvY/ZGAHWMZrYUq66VQBYMIYDFpDdJAOGSLyIPHZ2IQ==" crossorigin="anonymous" /> <div id="PictureHoverPanel" class="invisible absolute flex flex-col justify-center rounded-xl bg-gray-600 opacity-70"> <div class="flex justify-center"> <a class="bg-gray-800 px-2 py-1 text-white border border-red-800 font-semibold cursor-pointer">Remove</a> </div> </div> <img id="imagebox" class="w-48 h-48 rounded-xl md:w-64 md:h-64" src="/assets/photos/newyork1.jpg">
You can add #PictureHoverPanel
as well to the event listener.
Like this:
$(document).on("mouseover", "#imagebox, #PictureHoverPanel", function() {
$("#PictureHoverPanel").removeClass("invisible");
})
$(document).on("mouseover", "#imagebox, #PictureHoverPanel", function() { $("#PictureHoverPanel").removeClass("invisible"); }) $(document).on("mouseout", "#imagebox, #PictureHoverPanel", function() { $("#PictureHoverPanel").addClass("invisible"); })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.3/tailwind.min.css" integrity="sha512-wl80ucxCRpLkfaCnbM88y4AxnutbGk327762eM9E/rRTvY/ZGAHWMZrYUq66VQBYMIYDFpDdJAOGSLyIPHZ2IQ==" crossorigin="anonymous" /> <div id="PictureHoverPanel" class="invisible absolute flex flex-col justify-center rounded-xl bg-gray-600 opacity-70"> <div class="flex justify-center"> <a class="bg-gray-800 px-2 py-1 text-white border border-red-800 font-semibold cursor-pointer">Remove</a> </div> </div> <img id="imagebox" class="w-48 h-48 rounded-xl md:w-64 md:h-64" src="https://picsum.photos/seed/1/100">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.