How can I stop the page from jumping to top after clicking a link? I am running the following scripts. (I have a hunch that they are causing this behaviour)
<script type="text/javascript">
$(document).ready(function() {
$("#menu-primary-menu-1").append('<li class="menu-logo menu-item"><a href="<?php echo site_url(); ?>"><img src="<?php echo site_url(); ?>/wp-content/themes/redu/images/redu4.png"></a></li>');
});
</script>
<script type="text/javascript">
$(window).scroll(function() {
if ($(this).scrollTop() < 50) {
$('#menu-primary-menu-1').hide();
} else $('#menu-primary-menu-1').show();
});
</script>
<script type="text/javascript">
$(window).scroll(function() {
if ($(this).scrollTop() > 340) {
$('.arrow').css({
'display': 'none'
});
} else $('.arrow').show();
});
</script>
<script type="text/javascript">
$(".arrow").click(function() {
$('html,body').animate({
scrollTop: $(".row").offset().top
}, 'slow');
});
</script>
I tried this as a fix:
<script language="JavaScript" type="text/javascript">
var link = document.getElementsByTagName("a");
$(link).attr('onclick', 'bgenScroll();');
<!--
function bgenScroll() {
if (window.pageYOffset != null) {
st = window.pageYOffset + '';
}
if (document.body.scrollWidth != null) {
if (document.body.scrollTop) {
st = document.body.scrollTop;
}
st = document.documentElement.scrollTop;
}
setTimeout('window.scroll(0,st)', 10);
}
$('a').click(function(e) {
e.stopPropagation();
});
//-->
</script>
I am running them in a wordpress theme.
Fixed
This was not about # anchors. All the links scrolled the page to top when clicked.
I used this as a fix.