javascript - 使文本淡入并保持可见,直到鼠标离开容器

标签 javascript jquery html css

鼠标指针位于容器中时,我正在努力使文本淡入并保持可见并且只有当鼠标指针离开指定区域时,文本才会fadeOut,但由于某种原因它不起作用,文本将fadeOut即使鼠标在容器内。

我正在使用 Jquery lib 1.10.1 以及 Jquery ui 1.11.0

代码如下:

HTML

<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<div class="hold">
    <div class="conti">
        <div class="arrow-right"></div>
    </div>
    <div class="text-fade"></div>  
</div>

CSS

.hold{
    width: 142px;
    background: yellow;
    overflow: hidden;
    padding:10px;
}
.conti{
    width: 30px;
}
.arrow-right {
    width: 0; 
    height: 0; 
    border-top: 20px solid transparent;
    border-bottom: 20px solid transparent;
    border-left: 20px solid green;
}
.text-fade{
    display: none;
    float: right;
    margin-top:-30px;
    margin-left: 10px;
    margin-right:10px;
}

JS

$('.hold').mouseenter(function () {
    $('.arrow-right').effect("bounce", { direction:'right', times:3 }, 700);
    $('.text-fade').text("this is a test text").fadeIn(1000).css('display',"block");
});
$('.hold').mouseout(function () {
    $('.text-fade').fadeOut(1000);
});

这是我的 fiddle example 的链接

最佳答案

mouseout 由 child 触发,改用 mouseleave

$('.hold').mouseenter(function () {
    // var d = $('.arrow-right');
    // d.effect("bounce", { direction:'right', times:3 }, 700);
    $('.text-fade').text("this is a test text").fadeIn(1000);
});
$('.hold').mouseleave(function () {
    $('.text-fade').fadeOut(1000);
});

JS fiddle updated

关于javascript - 使文本淡入并保持可见,直到鼠标离开容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25035151/

相关文章:

javascript - 遍历对象数组,查找包含 2 个值的对象

javascript - 如何将自定义 SVG 图标添加到本地 fontawesome 库 (fontawesome-all.js)?

jquery - Grails 1.3.7中的jQuery

javascript - 尽管在 HTML 的视频标签中使用 "autoplay",但视频不会自动播放

javascript - 按名称/数量组织对象数组

javascript - 缩放时如何防止指定元素缩放 (iPhone)

jQuery - 如果不在 Web 服务器上则无法加载

jquery - 如何让 Photoswipe 从缩略图列表中识别整个图库

html - 为 Ruby on Rails 应用程序创建 Bootstrap 前端

android - webview 中的 HTML 实体