PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / scroll-to-top / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/scroll-to-top/frontend.js

47 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* Scroll To Top — frontend */
2 ( function () {
3 function init() {
4 document.querySelectorAll('.bkstt-wrap[data-trigger]').forEach(function(wrap) {
5 if (wrap._bksttInit) return;
6 wrap._bksttInit = true;
7
8 var btn = wrap.querySelector('.bkstt-btn');
9 if (!btn) return;
10
11 var trigger = parseInt(wrap.getAttribute('data-trigger'),10) || 400;
12 var smooth = wrap.getAttribute('data-smooth') !== '0';
13 var ticking = false;
14
15 function update() {
16 var scrollY = window.scrollY || window.pageYOffset;
17 if (scrollY > trigger) {
18 wrap.classList.add('bkstt-visible');
19 } else {
20 wrap.classList.remove('bkstt-visible');
21 }
22 ticking = false;
23 }
24
25 window.addEventListener('scroll', function() {
26 if (!ticking) {
27 requestAnimationFrame(update);
28 ticking = true;
29 }
30 }, {passive:true});
31
32 btn.addEventListener('click', function() {
33 window.scrollTo({ top: 0, behavior: smooth ? 'smooth' : 'auto' });
34 });
35
36 // Initial check
37 update();
38 });
39 }
40
41 if (document.readyState === 'loading') {
42 document.addEventListener('DOMContentLoaded', init);
43 } else {
44 init();
45 }
46 }() );
47