简体   繁体   English

用两个div淡出淡出不起作用

[英]fade in fade out with two divs does not work

I have the following code http://jsfiddle.net/largan/2n2Lf/25/ The idea is the div called soc_text to fade and fade out when hover on the soc_button div. 我有以下代码http://jsfiddle.net/largan/2n2Lf/25/这个想法是名为soc_text的div,当它悬停在soc_button div上时淡出并淡出。

I have this script, but it doesn't seems to work. 我有这个脚本,但它似乎不起作用。

$(document).ready(function()
{    
    $("div.soc_button").hover(
      function () {
        $("div.soc_text").fadeIn('slow');
      }, 
      function () {
        $("div.soc_text").fadeOut('slow');
      }
    );
});

Any ideas? 有任何想法吗? Thanks 谢谢

$(document).on("mouseover", "div.soc_button", function(){
    $(this).find("div.soc_text").fadeToggle("slow");
});

Here's the answer: 这是答案:

$(document).ready(function () {    
  $("div.soc_button img").hover(
    function () {
      console.log();
      $(this).parent().find('div.soc_text').fadeIn('slow');
    }, 
    function () {
      $(this).parent().find('div.soc_text').fadeOut('slow');
    }
  );
});

I guess the code is self explanatory, Regards 我想代码是自我解释的,问候

This applies the method to all matches with all div tags with soc_text css class 这将该方法应用于所有与soc_text css类的div标记匹配

 $("div.soc_text").fadeIn('slow');

Change this to 将此更改为

$(this).children('div.soc_text').fadeIn('slow');

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

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