Jquery 鼠标悬停在 div slideUp 上并将鼠标移出 div slideDown

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3654829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:50:07  来源:igfitidea点击:

Jquery mouse over div slideUp and mouse out div slideDown

jqueryhtmlslideupslidedown

提问by designer-trying-coding

Here is my code http://jsfiddle.net/AB6J3/7/you can see, edit, etc.

这是我的代码http://jsfiddle.net/AB6J3/7/你可以看到,编辑等。

When I roll over to red border box, the orange box should slide up and at mouse out it should slide down. it works well for the other way, but when I change slideDown to slideUp, it doesnt work :/ what am I missing?

当我滚动到红色边框框时,橙色框应该向上滑动,鼠标移出时它应该向下滑动。它适用于另一种方式,但是当我将 slideDown 更改为 slideUp 时,它不起作用:/我错过了什么?

Appreciate helps.

欣赏有帮助。

<!DOCTYPE html>
<html>
<head>
  <style>
div#monster { background:#de9a44; margin:3px; width:80px; height:40px; display:none; float:left; position:absolute; right:10px; top:0; }

#clickk {width:40px; height:40px; background:#ccc; position:absolute; top:0; right:10px;}
</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>

<div style="width:550px; padding:40px 0 0;margin:0 auto; border:1px solid #111; position:relative;">    
    <div id="monster"></div>
    <div id="clickk"></div><br />
    <div style="width:500px; height:300px; background-color:#ccc; margin:0 auto;"></div>
</div>

<script>
$("#clickk").hover(function () {
    if ($("#monster").is(":hidden")) {
        $("#monster").slideDown("fast");
    } else {
        $("#monster").slideUp("fast");
    }
});

</script>

</body>
</html>?

回答by Nick Craver

I think you're better off with some CSS tweaks here, like this:

我认为您最好在这里进行一些 CSS 调整,如下所示:

#monster { 
    background:#de9a44;
    width:80px; 
    height:60px; 
    display:none; 
    position:absolute;
    left: 0;
    bottom: 0;
}

#clickk {
    width:80px; 
    height:60px; 
    border:1px solid #cc0001; 
    background:transparent; 
    position:absolute; 
    top:0; 
    right:10px;
}

Then jQuery like this:

然后jQuery是这样的:

$("#clickk").hover(function () {
  $("#monster").slideToggle("fast");
});?

You can test it out here. ?

你可以在这里测试一下。?

回答by jwueller

You should try the following:

您应该尝试以下操作:

$("#clickk").hover(function () {
    $("#monster").slideUp("fast");
}, function() {
    $("#monster").slideDown("fast");
});

The second argument to .hover()is the mouseout-function.

的第二个参数.hover()是 mouseout 函数。