简体   繁体   English

用Jquery切换div使其保持可见

[英]After toggling div with Jquery make it stay visible

I have this jquery code: 我有这个jquery代码:

http://jsfiddle.net/y8wPw/60/ http://jsfiddle.net/y8wPw/60/

All I want is that after DIV with content opens, it must stay visible, so that I can go over it and use this div as a form( or some other purpose). 我想要的是,在打开内容的DIV之后,它必须保持可见,以便我可以查看它并将此div用作表单(或其他目的)。 But now, if I make a MOUSEOUT from Content div , it disappears. 但现在,如果我从Content div制作一个MOUSEOUT,它就会消失。

Jquery code: Jquery代码:

$(document).ready(function() {
    $(".body").hover(function () {
        $(".desc").toggle();
    })
})
$(document).ready(function() {
$(".body").hover(function () {
    $(".desc").show();
})

}) })

Why not try: 为什么不尝试:

$(document).ready(function() {
    $(".body").hover(function () {
        $(".desc").show();
    })
})

I have edited your js fiddle code by adding a wrapper and assigning the event to it. 我已经通过添加包装器并将事件分配给它来编辑您的js小提琴代码。 I guess that fixes you problem :) 我想这可以解决你的问题:)

updated the html to 将html更新为

<div id="wrap">
<div class="body">Hellp</div>
<div class="desc">Any content here!</div>
</div>
<div class="clear"></div>

updated the css 更新了CSS

#wrap{overflow:hidden}

updated the js 更新了js

$(document).ready(function() {
    $("#wrap").hover(function () {
        $(".desc").toggle();
    })
})

The link http://jsfiddle.net/RUtgE/1/ 链接http://jsfiddle.net/RUtgE/1/

Use .css('display', 'block') instead of .toggle() 使用.css('display', 'block')代替.toggle()

JSFiddle 的jsfiddle

You can use mouseenter instead of hover. 您可以使用mouseenter而不是悬停。 In this case it will show the first time you go over the "help" button, the next time it will close again. 在这种情况下,它会在您第一次显示“帮助”按钮时显示,下一次它将再次关闭。

Check out http://api.jquery.com/category/events/mouse-events/ for more mouse events to play with! 查看http://api.jquery.com/category/events/mouse-events/了解更多鼠标活动!

$(document).ready(function() {
    $(".body").hover(function () {
        $(".desc").show();
    })
    $(".close").click(function () {
        $(".desc").hide();
    })
    $(".wrap").mouseleave(function () {
        $(".desc").hide();
    })
})

http://jsfiddle.net/y8wPw/74/ http://jsfiddle.net/y8wPw/74/

This is what i was looking for! 这就是我想要的! With some of your help i managed to make it! 有了一些帮助,我成功了!

Thanks to all! 谢谢大家!

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

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