Skip to content

Commit

Permalink
Add Smooth Scroll Prevent option
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Nov 12, 2024
1 parent 1e9a10c commit 7c45505
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
16 changes: 15 additions & 1 deletion framework/library/astroid/Component/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ public static function smoothScroll(): void
if (!empty($easing)) {
$options[] = 'easing: '. Helper\Constants::$easing[$easing];
}
$prevent = $params->get('smooth_scroll_prevent', '');
$prevent_script = '';
if (!empty($prevent)) {
$prevent_arr = explode(',', $prevent);
if (count($prevent_arr)) {
$prevent_script .= 'jQuery(document).ready(function($){';
foreach ($prevent_arr as $key => $value) {
if (!empty(trim($value))) {
$prevent_script .= '$("'.trim($value).'").attr("data-lenis-prevent", "");';
}
}
$prevent_script .= '});';
}
}
$configs = implode(',', $options);
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$document = Framework::getDocument();
Expand All @@ -248,7 +262,7 @@ public static function smoothScroll(): void
.'};'
.'if (typeof ScrollTrigger !== \'undefined\') {initSmoothScrollingGSAP()} else {initSmoothScrolling()}';
$wa->registerAndUseStyle('astroid.lenis', 'astroid/lenis.min.css');
$wa->addInlineScript($script);
$wa->addInlineScript($script.$prevent_script);
}
}

Expand Down
3 changes: 1 addition & 2 deletions framework/library/astroid/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,7 @@ public function loadAnimation(): void
$wa->registerAndUseStyle('astroid.animate', 'astroid/animate.min.css');
if (Helper::isPro()) {
$this->loadImagesLoaded();
$this->loadGSAP('ScrollTrigger');
$wa->registerAndUseScript('astroid.animation.pro', 'media/astroidpro/assets/animations/js/index.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
$wa->registerAndUseScript('astroid.animation.pro', 'media/astroidpro/assets/animations/js/index.min.js', ['relative' => true, 'version' => 'auto']);
} else {
$wa->registerAndUseScript('astroid.animation', 'astroid/animate.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
}
Expand Down
1 change: 1 addition & 0 deletions framework/options/basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
<option value="easeInBounce">easeInBounce</option>
<option value="easeOutBounce">easeOutBounce</option>
</field>
<field astroidgroup="smooth_scroll" ngShow="[enable_smooth_scroll]=='1'" name="smooth_scroll_prevent" type="astroidtextarea" label="TPL_SMOOTH_SCROLL_PREVENT_LBL" description="TPL_SMOOTH_SCROLL_PREVENT_DESC" />
<field astroidgroup="cursor_options" name="enable_cursor_effect" type="astroidgetpro" label="ASTROID_CURSOR_EFFECT_ENABLE" description="ASTROID_CURSOR_EFFECT_ENABLE_DESC" />
</fieldset>
</fields>
Expand Down
2 changes: 2 additions & 0 deletions language/en-GB/en-GB.astroid.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ TPL_SMOOTH_SCROLL_SPEED_LBL="Scroll Speed"
TPL_SMOOTH_SCROLL_SPEED_DESC="This a number representing the amount of time in milliseconds that it should take to scroll 1000px. Scroll distances shorter than that will take less time, and scroll distances longer than that will take more time. The default is 1200ms."
ASTROID_SMOOTH_SCROLL_EASING="Scroll Easing"
ASTROID_SMOOTH_SCROLL_EASING_DESC="The easing function to use for the scroll animation, our default is custom but you can pick one from <a href=\"https://easings.net/en\" target=\"_blank\" rel=\"nofollow\">Easings.net</a>."
TPL_SMOOTH_SCROLL_PREVENT_LBL="Prevent Smooth Scroll"
TPL_SMOOTH_SCROLL_PREVENT_DESC="Prevent smooth scroll on specific elements by adding the class or id element. Seperated by comma. Ex: <code>#yourid, .yourclass</code>"
ASTROID_JD_BUILDER="Builder"

; Shortcuts
Expand Down

0 comments on commit 7c45505

Please sign in to comment.