I have 2 images in my html. 1 I show on the mobile version(if screen is smaller than 992px) and the other on desktop version.
I added an id to these images to use as an anchor. Everything works great on mobile devices but on the desktop version it doesn't wanna go to the anchor. Even though the id is there in the html.
This is what my images in html looks like:
<img id="wie" class="cool-image-2" src="source1" alt="">
<img id="wie" class="cool-image-2" src="source2" alt="">
These are the links: Dekstop menu:
<ul class="nav navbar-nav">
<li class="navbar-right"><a data-id="wie" href="#wie">Wie</a></li>
</ul>
Mobile menu:
<ul class="nav mobile-nav-bar">
<li class="navbar-right"><a data-id="cont" href="#contact">Contact</a></li>
</ul>
This is my jQuery:
jQuery(".nav li a").click(function(e) {
e.preventDefault();
$id = jQuery(this).attr("data-id");
jQuery("a.clicked").removeClass("clicked");
jQuery(this).addClass("clicked");
console.log($id);
jQuery('html, body').animate({
scrollTop: jQuery("#"+$id).offset().top
}, 1000);
});
Anyone has any idea why it doesn't work on desktop?
Many Thanks in advance!!