简体   繁体   English

需要使用JavaScript调整悬停效果

[英]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. 我有一个小问题需要修正,因为我想在div上应用悬停效果。 Heres my Js code. 这是我的Js代码。

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. 我的问题是,当您使用鼠标快速滚动div(在元素内和元素外)时,函数会堆叠起来并重复自身,直到它们与您将鼠标悬停在元素上的次数匹配为止。 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 看一下stop()函数

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/ 小提琴: http//jsfiddle.net/FvWTL/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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