Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将鼠标悬停在alink上并设置div动画_Jquery - Fatal编程技术网

Jquery 将鼠标悬停在alink上并设置div动画

Jquery 将鼠标悬停在alink上并设置div动画,jquery,Jquery,嗨,为了得到我工作所需要的东西,我已经停下来了 基于: $(".test a").hover(function(){ $(this).toggle({ height: "200px" }); }, function() { var currentTab = $(this).attr('href'); $(this).stop(true, false).animate({ height: "100px" }); }); }); &l

嗨,为了得到我工作所需要的东西,我已经停下来了

基于:

$(".test a").hover(function(){
        $(this).toggle({ height: "200px" });
    }, function() {
        var currentTab = $(this).attr('href');
        $(this).stop(true, false).animate({ height: "100px" });
    });
});

<div class="test">
  <a href="#one">1</a>
  <a href="#two">2</a>
  <a href="#three">3</a>
</div>

您需要重新声明变量activeTab,因为它只存在于mouseenter的作用域中,而不存在mouseout

$(".test a").hover(function(){      
          var activeTab = $(this).attr("href"); 
          $(activeTab).toggle({ height: "200px" });   
     }, 
     function() {
          var activeTab = $(this).attr("href"); 
          $(activeTab).stop(true, false).animate({ height: "100px" });   
     }); 
});
这里有一些错误。。。一是,数一数你的括号

$(".test a").hover(function(){
    var activeTab = $(this).attr("href"); 
    $(activeTab).toggle({ height: "200px" });
},
function() {
    $(activeTab).stop(true, false).animate({ height: "100px" });
});
}); // too many closing brackets
第二个是var activeTab超出了第二个函数的作用域。因此,您需要在第二个函数中重新定义var activeTab:

这应该起作用:

$(".test a").hover(function(){
    var activeTab = $(this).attr("href"); 
    $(activeTab).toggle({ height: "200px" });
},
function() {
    var activeTab = $(this).attr("href"); 
    $(activeTab).stop(true, false).animate({ height: "100px" });
});
$(".test a").hover(function(){
    var activeTab = $(this).attr("href"); 
    $(activeTab).toggle({ height: "200px" });
},
function() {
    $(activeTab).stop(true, false).animate({ height: "100px" });
});
}); // too many closing brackets
$(".test a").hover(function(){
    var activeTab = $(this).attr("href"); 
    $(activeTab).toggle({ height: "200px" });
},
function() {
    var activeTab = $(this).attr("href"); 
    $(activeTab).stop(true, false).animate({ height: "100px" });
});