简体   繁体   中英

Need to tweak hover effect with JavaScript

I have a little issue I need to fix as I'm trying to apply a hover effect on a div. Heres my Js code.

function fan_art_in () {
$(".fan-art-text").fadeIn("slow")
};


function fan_art_out () {
  $(".fan-art-text").fadeOut("fast")
};


$(".box-1").hover(fan_art_in, fan_art_out);

My issue with this is that when you quickly scroll over the div with the mouse (in and out of the element) the functions kind of stack up and repeat themselves until they match the number of times you hovered over the element. How can I make it so that once the mouse leaves the element it stops repeating the functions?

have a look at the stop() function

function fan_art_in () {
$(".fan-art-text").stop().fadeIn("slow")
};


function fan_art_out () {
  $(".fan-art-text").stop().fadeOut("fast")
};


$(".box-1").hover(fan_art_in, fan_art_out);

fiddle: http://jsfiddle.net/FvWTL/

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM