在鼠标离开触发器后保持Div可见(jQuery)
Keep Div visible after mouse moves from trigger (jQuery)
我目前正在构建一个布局,其中我在<nav><ul><li><a>
元素中有几个'触发器' -每个显示一个<div>
,有效地位于'后面' (z-index)。
我需要div (#showme和#showmetoo)保持可见,即使用户将鼠标从各自的触发器(。触发器,.thenextrigger) -div将包含内容/链接。
另外,当用户从一个触发器移动到下一个触发器时,显示的div应该改变。
<header>
<nav>
<ul>
<li><a class="thetrigger">Show Me That Thing</a></li>
<li><a class="thenexttrigger">Show Me That Thing</a></li>
</ul>
</nav>
<div id="showme">Yay, this thing</div>
<div id="showmetoo">and this thing</div>
</header>
CSS header {
width: 100%;
height: 300px;
position: relative;
background: red;
z-index: 1;
}
nav {
position: absolute;
top: 10px;
left: 30px;
z-index: 3;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
padding: 30px;
}
.thetrigger, .thenexttrigger {
color: white;
}
#showme {
display: none;
background: blue;
color: white;
position: absolute;
top: 0;
left: 0;
height: 300px;
width: 100%;
z-index: 2;
}
#showmetoo {
display: none;
background: green;
color: white;
position: absolute;
top: 0;
left: 0;
height: 300px;
width: 100%;
z-index: 2;
}
jQuery $(document).ready(function() {
$('.thetrigger').hover(function() {
$('#showme').fadeIn();
}, function() {
$('#showme').fadeOut();
});
$('.thenexttrigger').hover(function() {
$('#showmetoo').fadeIn();
}, function() {
$('#showmetoo').fadeOut();
});
});
http://jsfiddle.net/richardblyth/24bcs/Demo
听起来你想让div保持直到下一个触发器悬停。
如果您为触发器使用一个类,并使用data找到它们各自的div,则可以使用更少的jQuery。有了这个,你可以添加任意多的触发器和相应的div,而不必编写更多的jQuery。
HTML<header>
<nav>
<ul>
<li><a class="trigger" data-show="pane1">Show Me That Thing</a></li>
<li><a class="trigger" data-show="pane2">Show Me That Thing</a></li>
</ul>
</nav>
<div class="pane" data-show="pane1" id="showme">Yay, this thing</div>
<div class="pane" data-show="pane2" id="showmetoo">and this thing</div>
</header>
jQuery $(function(){
$('.trigger').on('mouseover', function(){
// show the desired pane and hide its siblings
$('.pane[data-show="' + $(this).data('show') + '"]').fadeIn().siblings('.pane').fadeOut();
});
});
如果我理解你的问题的话,我认为你真正想要的是,当你将鼠标悬停在与#showmetoo元素相关联的触发器元素中时隐藏另一个#showme元素。
:
$(document).ready(function() {
$('.thetrigger').hover(function() {
$('#showme').fadeIn();
$('#showmetoo').fadeOut();
});
$('.thenexttrigger').hover(function() {
$('#showmetoo').fadeIn();
$('#showme').fadeOut();
});
});http://jsfiddle.net/4N26S/
相关文章:
- 当Div可见时使用Javascript
- 如何确定滚动DIV中的可见DOM元素
- 基本 Jquery - 如果 TD 中存在文本,则使 DIV 可见
- WebGL Three.js在画布Div可见之前,不会加载某些内容
- 需要切换2个DIV的DIV可见性
- 如何切换DIV元素的可见性
- 滚动上的交替 DIV 可见性
- 如何根据另一个 DIV 内容的可见性显示 DIV 内容
- 当它可见时自动淡出 Div
- 一次只能有一个活动类和可见 Div
- 如何在 DIV 中添加文本,但不使其可见或使用页面上的任何空间
- Div 显示:无 - 只想在内容可见时加载内容
- JavaScript - DIV的可见文本
- 无法手动将 DIV 元素上的可见性设置为 true.“TH:IF”问题
- Brightcove在Div可见时开始播放
- 使用 jquery 根据链接单击切换 DIV 可见性
- 如何在回发后保持DIV可见
- 使图像(位置:固定)仅在DIV内部可见
- 可点击下拉列表不可见DIV
- 动态过滤可见Div元素