سؤال

هنا هو بلدي رمز http://jsfiddle.net/AB6J3/7/ يمكنك أن ترى, تحرير, الخ.

عندما يتدحرج إلى الحدود الحمراء مربع, مربع برتقالي يجب أن تنزلق في الماوس من ذلك أن تنزلق.أنه يعمل بشكل جيد على طريقة أخرى, ولكن عندما أقوم بتغيير slideDown إلى slideUp ، فإنه لا يعمل :/ ما أنا في عداد المفقودين ؟

نقدر يساعد.

<!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>​
هل كانت مفيدة؟

المحلول

أعتقد أنك أفضل حالا مع بعض القرص 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;
}

ثم مسج مثل هذا:

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

يمكنك اختبار بها هنا. ​

نصائح أخرى

يجب أن تحاول التالية:

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

الحجة الثانية أن .hover() هو mouseout-وظيفة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top