Reputation: 67
By default, Divi smooth-scrolls the page to sections from anchor links. I need the page to "jump" directly to the section instantly without any scroll animation.
Example: https://stanfordimapro.wpengine.com [Nav links at top]
I've added this code:
$('#nav-section a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var $trget = $(target);
$('html, body').animate ({
scrollTop: $trget
}, 0, 'linear', function () {
window.location.hash = target;
});
});
That does make it instantly jump to the section but there's still a odd scroll up afterwards.
Ideally I'd like to remove the Divi scroll behavior entirely, but I can't find exactly where that is in the Divi theme files. It's likely related to "et_pb_smooth_scroll" in Divi/js/custom.js and/or Divi/js/scripts.js
Update: I found a few of these ( et_pb_smooth_scroll(i,a,800) ) in scripts.js and changed 800 to 0. That stopped the scroll animation, but I'm wondering how I can do that without editing theme files directly.
Upvotes: 0
Views: 1780
Reputation: 87
Try this solution:
<script>
jQuery( document ).ready(function() {
var previousSmoothScroll = window.et_pb_smooth_scroll;
window.et_pb_smooth_scroll = function($target, $top_section, speed, easing) {
previousSmoothScroll($target, $top_section, 0, 'linear' );
}
});
</script>
Upvotes: 1