Last active
September 20, 2019 04:08
-
-
Save carlosonweb/284c4d01afb247225fefb653169a821b to your computer and use it in GitHub Desktop.
Code Tweaks for Beaver Builder Smooth Scrolling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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