[英]How to have “col-md-6” div appear when hovering over list items in separate div
Here is the code i have on my HTML doc. 这是我在HTML文档中的代码。 I have been trying to get this hover action to work, i have only gotten it to work so far when the description is a child of the li tag, which is not what i want.
我一直在尝试使此悬停操作起作用,但直到描述是li标记的子代时,我才使它起作用,这不是我想要的。 I want the description to be shown as a separate div.
我希望说明显示为单独的div。
<div class="row">
<div class="col-md-6 wow fadeIn header-left" data-wow-delay=".5s" data-wow-duration="2s">
<h2>Services</h2>
<ul class="services-list flex">
<!--Hover this list item for description div to appear-->
<li id="item-1" class="wow fadeIn" data-wow-delay="1s"><h5><a href="#">Lighting System Design</a></h5>
<div class="wow fadeIn" data-wow-delay=".1s" id="lightingDesign">
</li>
</ul>
</div>
<!--Description div i want to appear when hover on #item-1-->
<div class="col-md-6 header-left wow fadeIn" id="description-1">
<h4>Lighting System Design</h4>
<p>Determining the equipment and programing required that meet interior anenter code hered exterior lighting specifications.</p>
</div>
</div>
</div>
Since the element you want to display isn't adjacent to or inside of the element you want to toggle, you can't use CSS, but you can use javascript. 由于要显示的元素不与要切换的元素相邻或不位于元素内,因此不能使用CSS,但可以使用javascript。 I changed the
href
attribute of the link to be the id
of the element to toggle. 我将链接的
href
属性更改为要切换的元素的id
。 You could also use a data-*
attribute instead if you wanted to leave the href
value alone or change it to something else. 如果您想单独保留
href
值或将其更改为其他值,也可以使用data-*
属性。
$('.services-list a').hover(function() { $($(this).attr('href')).stop().fadeToggle(); })
.description { display: none; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="row"> <div class="col-md-6 wow fadeIn header-left" data-wow-delay=".5s" data-wow-duration="2s"> <h2>Services</h2> <ul class="services-list flex"> <li id="item-1" class="wow fadeIn" data-wow-delay="1s"> <h5><a href="#description-1">Lighting System Design</a></h5> <div class="wow fadeIn" data-wow-delay=".1s" id="lightingDesign"> </li> </ul> </div> <!--Description div i want to appear when hover on #item-1--> <div class="description col-md-6 header-left wow fadeIn" id="description-1"> <h4>Lighting System Design</h4> <p>Determining the equipment and programing required that meet interior anenter code hered exterior lighting specifications.</p> </div> </div> </div>
You can do this by using jQuery mouseover
and mouseleave
function. 您可以通过使用jQuery
mouseover
和mouseleave
函数来做到这一点。 Check below snippet. 检查以下代码段。
$('#item-1').on('mouseover', function() { $('#description-1').fadeIn("fast"); }).on('mouseleave', function() { $('#description-1').fadeOut("fast"); });
#description-1 { display: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div class="container"> <div class="row"> <div class="col-md-6 wow fadeIn header-left" data-wow-delay=".5s" data-wow-duration="2s"> <h2>Services</h2> <ul class="services-list flex"> <!--Hover this list item for description div to appear--> <li id="item-1" class="wow fadeIn" data-wow-delay="1s"> <h5><a href="#">Lighting System Design</a></h5> <div class="wow fadeIn" data-wow-delay=".1s" id="lightingDesign"></div> </li> </ul> </div> <!--Description div i want to appear when hover on #item-1--> <div class="col-md-6 header-left wow fadeIn" id="description-1"> <h4>Lighting System Design</h4> <p>Determining the equipment and programing required that meet interior anenter code hered exterior lighting specifications.</p> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.