jquery slide to attribute with specific data attribute value
Posted
by
Alex M
on Stack Overflow
See other posts from Stack Overflow
or by Alex M
Published on 2013-11-10T15:41:18Z
Indexed on
2013/11/10
15:53 UTC
Read the original article
Hit count: 366
jQuery
|custom-data-attribute
Ok, so I have the following nav with absolute urls:
<ul class="nav navbar-nav" id="main-menu">
<li class="first active"><a href="http://example.com/" title="Home">Home</a></li>
<li><a href="http://example.com/about.html" title="About">About</a></li>
<li><a href="http://example.com/portfolio.html" title="Portfolio">Portfolio</a></li>
<li class="last"><a href="example.com/contact.html" title="Contact">Contact</a></li>
</ul>
and then articles with the following data attributes:
<article class="row page" id="about" data-url="http://example.com/about.html">
<div class="one">
</div>
<div class="two"
</div>
</article>
and when you click the link in the menu I would like to ignore the fact it is a hyperlink and slide to the current article based on its attribute data-url.
I started with what I think is the obvious:
$('#main-menu li a').on('click', function(event) {
event.preventDefault();
var pageUrl = $(this).attr('href');
)};
and have tried find and animate but then I don't know how to reference the article with data-url="http://example.com/about.html".
Any help would be most appreciated.
Thanks
© Stack Overflow or respective owner