我有一些链接(见下文),其中我放置了data-navigation
属性,而我正在尝试做的是data-section
属性slidesDown
基于它的数据导航父级
HTML
<ul class="main-navbar-right">
<li><a href="#" data-navigation="home">Home</a></li>
<li><a href="#" data-navigation="explore">Explore</a></li>
<li><a href="#" data-navigation="news">News</a></li>
</ul>
<section id="-navbar-home" data-section="home">
<p>Home content</p>
</section>
<section id="-navbar-explore" data-section="explore">
<p>Home explore</p>
</section>
<section id="-navbar-explore" data-section="news">
<p>Home news</p>
</section>
CSS
#-navbar-home,
#-navbar-explore,
#-navbar-news {
display: none;
}
JavaScript / jQuery(我到目前为止,无法继续)
$(document).ready(function() {
$('li > a').hover(function() {
var navigation = $("a").data("navigation");
var section = $("section").data("section");
$(section).slideDown();
});
});
JS Fiddle
http://jsfiddle.net/66qz2by8/
答案 0 :(得分:1)
尝试使用Attribute Equals Selector [name="value"]
var navigation = $(this).data("navigation");
var section = $("section[data-section=" + navigation + "]");
$(section).slideDown();