Skip to content

Instantly share code, notes, and snippets.

@carlosonweb
Last active September 20, 2019 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosonweb/284c4d01afb247225fefb653169a821b to your computer and use it in GitHub Desktop.
Save carlosonweb/284c4d01afb247225fefb653169a821b to your computer and use it in GitHub Desktop.
Code Tweaks for Beaver Builder Smooth Scrolling
/**
*
* Tweak the code here:
*
* https://kb.wpbeaverbuilder.com/article/634-smooth-scrolling-tweaks-with-code
*
* to make it work when the anchor link is coming from another page.
*
*/
(function($){
var win = $( window ),
hashLink = window.location.hash,
offset = 50;
var bbScroll = function(){
if ( 'undefined' != typeof FLBuilderConfig ) {
if ( 'undefined' === typeof FLBuilderLayout ) {
return;
}
FLBuilderLayoutConfig.anchorLinkAnimations.offset = offset;
}
};
if ( 'undefined' !== typeof FLBuilderConfig && hashLink.length ) {
if ( FLBuilderLayout._isMobile() && win.width() < 992 ) {
offset = 0;
} else {
offset += 25;
FLBuilderLayoutConfig.anchorLinkAnimations.duration = 500;
FLBuilderLayoutConfig.anchorLinkAnimations.easing = 'swing';
FLBuilderLayoutConfig.anchorLinkAnimations.offset = offset;
}
if ( $( 'body.admin-bar' ).length > 0 ) {
offset += 32;
}
FLBuilderLayout._scrollToElement( $(hashLink) );
} else {
bbScroll();
}
win.on( 'resize', bbScroll );
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment