[英]Hide all sibilings of a DIV when mouse enter/hover to a link and Show the particular DIV
I have separated buttons and DIV's representing each button. 我将按钮分开,并且DIV代表每个按钮。 I need to show only the particular DIV when hover or mouse enter on it's corresponding button.
当悬停或在相应按钮上输入鼠标时,我只需要显示特定的DIV。 The code is shown below,
代码如下所示,
<ul class="icon-list">
<li><a href="#" id="btn-ftr-5"><div class="circle"><i class="fa fa-user fa-3"></i></div></a></li>
<li><a href="#" id="btn-ftr-4"><div class="circle"><i class="fa fa-tasks fa-3"></i></div></a></li>
<li><a href="#" id="btn-ftr-3"><div class="circle"><i class="fa fa-gift fa-3"></i></div></a></li>
<li><a href="#" id="btn-ftr-2"><div class="circle"><i class="fa fa-music fa-3"></i></div></a></li>
</ul>
And the DIVs is below, DIV在下面,
<div class="row feature-content-original" id="ftr-1">
<div class="col-md-5 feature-title" id="#title-ftr">
<h2>Event Details</h2>
</div>
<div class="col-md-7 feature-info">
<p>Welcome to your NuEvents Snapshot page.
From your event management snapshot page, you can get a quick overview of al
l your event statistics. Monitor your RSVP/Food/Drink/Song activity in real time.
From your Snapshot page you can create a new task, memo, or appointment with ease.</p>
</div>
</div>
<div class="row feature-content hidden" id="ftr-2">
<div class="col-md-5 feature-title" id="#title-ftr">
<h2>Food And Drinks</h2>
</div>
<div class="col-md-7 feature-info">
<p>From your event management snapshot page, you can get a quick overview of al
l your event statistics. Monitor your RSVP/Food/Drink/Song activity in real time.
From your Snapshot page you can create a new task, memo,
your RSVP/Food/Drink/Song activity in real time.
From your Snapshot page you can create a new task, memor appointment with ease.</p>
</div>
</div> <!--etc -->
And I have 2 classes for DIVs to show and hide as 'showftr' and 'hidden' 我有2个DIV类,分别以“ showftr”和“ hidden”显示和隐藏
The following code is not working. 以下代码不起作用。 I need your help to get a result.
我需要您的帮助才能取得结果。
<script>
$(document).ready(function() {
$('#btn-ftr-2').mouseenter(function() {
$('#ftr-2').addClass('showftr');
}, function() {
$('#ftr-2').removeClass('hidden');
}, function(){
$('#ftr-2').sibilings().addClass('hidden');
}
});
});
</script>
Here is my attempt, if I understood it correctly: 如果我正确理解,这是我的尝试:
$('a[id^=btn-ftr-]').hover(function() {
var id = $(this).attr('id');
id = id.substr(id.lastIndexOf('-') + 1, id.length);
$('div[id^=ftr-]').removeClass('showftr').addClass('hidden');
$('div[id=ftr-' + id + ']').removeClass('hidden').addClass('showftr');
}, function() {
$('div[id^=ftr-]').removeClass('hidden').addClass('showftr');
});
You want something like that? 你想要那样的东西吗?
Use the same button's id and div's class to be shown/hidden. 使用相同按钮的ID和div的类进行显示/隐藏。 You can get show/hide funtion with the jquery script alone.
您可以仅使用jquery脚本获得显示/隐藏功能。
$(document).ready(function () {
$('.feature-content').hide(0);
$('.feature-content').eq(0).show(0);
$('.icon-list li a').on('mouseover', function () {
$('.feature-content').hide(0);
var get_id = $(this).attr('id');
$('.feature-content.'+get_id).show(0);
});
});
<ul class="icon-list">
<li>
<a href="#" id="div-ftr-5"><div class="circle"><i class="fa fa-user fa-3"></i> Event Detail</div></a>
</li>
<!-- ... -->
</ul>
<div class="row feature-content div-ftr-5">
<div class="col-md-5 feature-title" id="#title-ftr">
<h2>Event Details</h2>
</div>
<div class="col-md-7 feature-info">
<p>Welcome to your NuEvents Snapshot page. From your event management snapshot page, you can get a quick overview of al l your event statistics. Monitor your RSVP/Food/Drink/Song activity in real time. From your Snapshot page you can create a new task, memo, or appointment with ease.</p>
</div>
</div>
<!--etc -->
Since you have a repeated structure, you can simplify your code by adding additional common classes to the elements 由于您具有重复的结构,因此可以通过向元素添加其他通用类来简化代码
A class btn-ftr
is added to all buttons where as a class ftr
is added to all the div's. btn-ftr
类添加到所有按钮,而ftr
类添加到所有div。
jQuery(function($) { var $contents = $('.ftr') $('.btn-ftr').hover(function() { var tid = this.id.replace('btn-', ''), $target = $('#' + tid); $contents.not($target).addClass('hidden'); $target.addClass('showftr').removeClass('hidden'); }, function() { $contents.filter('.hidden').removeClass('hidden'); var tid = this.id.replace('btn-', ''); $('#' + tid).removeClass('showftr'); }) })
.hidden { display: none; }
<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css"> <ul class="icon-list"> <li><a href="#" id="btn-ftr-1" class="btn-ftr"><div class="circle"><i class="fa fa-user fa-3"></i></div></a></li> <li><a href="#" id="btn-ftr-2" class="btn-ftr"><div class="circle"><i class="fa fa-tasks fa-3"></i></div></a></li> </ul> <div class="row feature-content-original ftr" id="ftr-1"> <div class="col-md-5 feature-title" id="#title-ftr"> <h2>Event Details</h2> </div> <div class="col-md-7 feature-info"> <p>Welcome to your NuEvents Snapshot page. From your event management snapshot page, you can get a quick overview of al l your event statistics. Monitor your RSVP/Food/Drink/Song activity in real time. From your Snapshot page you can create a new task, memo, or appointment with ease.</p> </div> </div> <div class="row feature-content hidden ftr" id="ftr-2"> <div class="col-md-5 feature-title" id="#title-ftr"> <h2>Food And Drinks</h2> </div> <div class="col-md-7 feature-info"> <p>From your event management snapshot page, you can get a quick overview of al l your event statistics. Monitor your RSVP/Food/Drink/Song activity in real time. From your Snapshot page you can create a new task, memo, your RSVP/Food/Drink/Song activity in real time. From your Snapshot page you can create a new task, memor appointment with ease.</p> </div> </div> <!--etc -->
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.