Hello. I can not understand what the problem is. There are anchors on the page linked to links:
<aside class="left-content"> <div class="nav"> <ul> <li><a href="#treby" class="treby">Православные требы</a></li> <li><a href="#moleben" class="moleben">Молебен</a></li> <li><a href="#sorokoust" class="sorokoust">Сорокоуст</a></li> <li><a href="#svecha" class="svecha">Свеча</a></li> <li><a href="#pozhertvovanie" class="pozhertvovanie">Пожертвование</a></li> </ul> </div>
The script hides articles, except the selected one and scrolls to id:
$(".nav").on("click","a", function (event) { event.preventDefault(); var id = $(this).attr('href'); var top = $(id).offset().top; $('body,html').animate({scrollTop: top}, 1500); $('.content').hide(); $('.content.' + this.className).show(); });
Html markup:
<div id="svecha"></div> <div class="content svecha" style=""> <div class="sec" id="article-89"> <div class="title">Свеча</div> <div class="sec" id="to_print"><div class="timage-svecha"><img alt="Свеча" src="/static/images/svecha.jpg" style="height:211px;width:281px" title="Свеча"></div> <p> ... </p> </div> </div>
The problem is that when you click on the links on the page, it scrolls away to the footer, then to the middle of the content. Once can work normally. when re-moving go down. A must scroll to
<div id="svecha"></div>
hide/show
elements with hiding and display, and only then calculate the position of the target elementtop = $(id).offset().top
and actually start the animation$('body,html').animate({scrollTop: top}, 1500)
- Konstantin Basharkevich