[英]Change <ul> visibility on hover of adjacent <ul> <li>
I am trying to change the visibility of multiple <ul>
from an adjacent <ul>
but I cannot figure out a way to do it without a bunch of .hide()
and .show()
calls. 我想多的可见性改变
<ul>
从相邻的<ul>
但我不能想出一个办法做到这一点没有一堆.hide()
和.show()
调用。 I also thought about HTML event attributes but thought that would be just as bad. 我也考虑过HTML事件属性,但也认为同样糟糕。
Can anyone point me in the right direction? 谁能指出我正确的方向? The first col-sm-3 is my hover links, the second col-sm-3 is where I am trying to have it changed.
第一个col-sm-3是我的悬停链接,第二个col-sm-3是我试图对其进行更改的地方。 I already figured out how to have the image in the third col change.
我已经弄清楚了如何更改第三列的图像。
http://jsfiddle.net/Wy22s/453/ http://jsfiddle.net/Wy22s/453/
HTML: HTML:
<div class="container">
<div class="row">
<div class="col-sm-3">
<ul class="projectslist">
<li class="tdSwOV7"><p>Project1</p></li>
<li class="QEJfRzZ"><p>Project2</p></li>
</ul>
</div>
<div class="col-sm-3">
<ul class="attributeslist" id="project1attributes">
<li><p>Custom Template Design</p></li>
<li><p>Reponsive Mobile Design</p></li>
</ul>
<ul class="attributeslist" id="project2attributes">
<li><p>Reponsive Mobile Design</p></li>
<li><p>SEO Keyword Research</p></li>
</ul>
</div>
<div class="col-sm-6">
<div class="portfolio_bg">
<ul class="imageslist">
<img id="myImage" src="http://i.imgur.com/tdSwOV7.png" class="img-responsive" />
</ul>
</div>
</div>
</div>
</div>
jQuery: jQuery的:
$( document ).ready(function() {
$('.projectslist li').mouseover(function() {
tempUrl = $(this).attr('class')
$('.imageslist img').attr('src', 'http://i.imgur.com/' + tempUrl + '.png')
});
});
I would decorate the projects with project attributes as classes. 我将用项目属性作为类来装饰项目。 And I would decorate the attributes with a data-type attributes.
我会用数据类型的属性来修饰属性。 Then on hover, I would hide all the project attributes and then show those attribute which exist as classes on the project.
然后在悬停时,我将隐藏所有项目属性,然后显示那些在项目中作为类存在的属性。 Here's how it would work:
运作方式如下:
<div class="container">
<div class="row">
<div class="col-sm-3">
<ul class="projectslist">
<li class="tdSwOV7 pr-seo"><p>Project1</p></li>
<li class="QEJfRzZ pr-custom pr-seo"><p>Project2</p></li>
</ul>
</div>
<div class="col-sm-3">
<ul class="attributeslist" id="project1attributes">
<li data-type="pr-custom"><p>Custom Template Design</p></li>
<li data-type="pr-responsive"><p>Reponsive Mobile Design</p></li>
</ul>
<ul class="attributeslist" id="project2attributes">
<li data-type="pr-responsive"><p>Reponsive Mobile Design</p></li>
<li data-type="pr-seo"><p>SEO Keyword Research</p></li>
</ul>
</div>
<div class="col-sm-6">
<div class="portfolio_bg">
<ul class="imageslist">
<img id="myImage" src="http://i.imgur.com/tdSwOV7.png" class="img-responsive" />
</ul>
</div>
</div>
</div>
</div>
<script>
$( document ).ready(function() {
$('.projectslist li').mouseover(function() {
var $theli = $(this);
$('.attributeslist li').hide()
.each(function(i, e) {
if ($theli.hasClass($(e).attr('data-type')))
$(e).show();
});
tempUrl = $(this).attr('class');
$('.imageslist img').attr('src', 'http://i.imgur.com/' + tempUrl + '.png');
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.