PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.4.5
Easy Elements for Elementor – Addons & Website Templates v1.4.5
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / navigation-menu / js / eel-sticky-header.js

eel-sticky-header.js in Easy Elements for Elementor – Addons & Website Templates 1.4.5, at widgets/navigation-menu/js/eel-sticky-header.js

93 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 function initStickyHeaderScript($scope) {
3 var header = $('header.easy-site-header');
4 var page = $('#page');
5 var topbar = $('.topbar-sticky-hide-yes');
6 //var isFixedHeader = $('body').hasClass('easyel-fixed-header, rivora-sidebar-menu');
7 var isFixedHeader = $('body').is('.easyel-fixed-header, .rivora-sidebar-menu');
8
9 if (!header.length || !page.length) {
10 return;
11 }
12
13 //header.addClass("eel-sticky-header-on");
14
15 function updatePaddingAndMargin(scrollDirection, scroll) {
16 var headerHeight = header.outerHeight();
17 var topbarHeight = topbar.length ? topbar.outerHeight() : 0;
18 var isTopSticky = header.hasClass('eel-fixed-top-sticky');
19
20 // page padding-top
21 if (typeof eelStickyHeaderSettings !== 'undefined' && eelStickyHeaderSettings.enablePadding) {
22 if (!isFixedHeader) {
23 page.css('padding-top', headerHeight + 'px');
24 } else {
25 page.css('padding-top', '');
26 }
27 }
28
29 // fixed-top-sticky
30 if (isTopSticky) {
31 if (scroll > 100) {
32 header.addClass('eel--fixed-top-sticky');
33 header.css('margin-top', `-${topbarHeight}px`);
34 } else {
35 header.removeClass('eel--fixed-top-sticky');
36 header.css('margin-top', '0px');
37 }
38 return;
39 }
40
41 // sticky behavior
42 if (header.hasClass('eel-up-scroll')) {
43 header.css('margin-top', `-${topbarHeight}px`);
44 } else {
45 header.css('margin-top', '0px');
46 }
47 }
48
49 let lastScroll = 0;
50 const stickyScrollThreshold = 50;
51
52 function sticky_header() {
53 let scroll = $(window).scrollTop();
54 let isTopSticky = header.hasClass('eel-fixed-top-sticky');
55 let scrollDirection = scroll > lastScroll ? 'down' : 'up';
56
57 if (isTopSticky) {
58 header.addClass('eel-sticky-header');
59 updatePaddingAndMargin(scrollDirection, scroll);
60 lastScroll = scroll;
61 return;
62 }
63
64 if (scroll > stickyScrollThreshold) {
65 header.addClass('eel-sticky-header');
66 if (scroll > lastScroll) {
67 header.removeClass('eel-up-scroll').addClass('eel-down-scroll');
68 } else {
69 header.removeClass('eel-down-scroll').addClass('eel-up-scroll');
70 }
71 } else {
72 header.removeClass('eel-sticky-header eel-up-scroll eel-down-scroll');
73 }
74
75 updatePaddingAndMargin(scrollDirection, scroll);
76 lastScroll = scroll;
77 }
78
79 $(document).ready(function() {
80 updatePaddingAndMargin('up', 0);
81 sticky_header();
82 });
83
84 $(window).on('scroll resize', function() {
85 sticky_header();
86 });
87 }
88
89 $(window).on('elementor/frontend/init', function() {
90 elementorFrontend.hooks.addAction('frontend/element_ready/global', initStickyHeaderScript);
91 });
92 })(jQuery);
93