[NODEBB] Scroll Button
-
Hi @phenomlab
I feel like I’ve been abused, but too bad, I’m starting…
I saw that you had a scroll button that appears/disappears automatically.
I see this is a JS/CSS/HTML code.
I also saw that this button does not appear in the topics (probably acting as a duplicate with the existing one one NodeBB). I’m also interested with that element.
On the other hand it’s very practical in the long page categories for example.
Is it possible to share this code or not?
Thanks in advance.
Good evening!!
-
@downpw Of course it’s possible to share
Here’s the CSS
#btt { display: inline-block; background: rgba(0, 0, 0, 0.2); width: 50px; height: 50px; text-align: center; border-radius: 4px; position: fixed; bottom: 50px; right: 30px; transition: background-color .3s, opacity .5s, visibility .5s; opacity: 0; visibility: hidden; } #btt.show { opacity: 1; visibility: visible; z-index: 10000; color: #ffffff; } a#btt.show:hover { box-shadow: inset 0px 0px 0px 1px #4F707A !important; } a#btt i { position: absolute; top: 32%; left: 35%; }
Obviously, style to suit your own site
And here’s the JS
$(window).on('action:ajaxify.end', function (data) { var matched = false; var btn = $('#btt'); var bar = $('.reading-meter'); bar.removeClass('show'); $(window).scroll(function () { if ($(window).scrollTop() > 300) { btn.addClass('show'); bar.addClass('show'); } else { btn.removeClass('show'); bar.removeClass('show'); } if (window.location.href.indexOf("topic") > -1) { if (matched == false) { console.log("This is a topic, so hide the scroll top feature"); matched = true; } btn.removeClass('show'); } }); btn.on('click', function (e) { e.preventDefault(); $('html, body').animate({ scrollTop: 0 }, '300'); }); });
Some points
bar.addClass('show');
andbar.removeClass('show');
are only required if you are using theprogress-meter
code. Essentially, the two are designed to work together with the code above, but it won’t matter that much if you aren’t using the progress-meter (however, you may land up with some errors in the console). -
@phenomlab said in [NODEBB] Scroll Button:
Some points
bar.addClass(‘show’); and bar.removeClass(‘show’); are only required if you are using the progress-meter code. Essentially, the two are designed to work together with the code above, but it won’t matter that much if you aren’t using the progress-meter (however, you may land up with some errors in the console).You talk about Reading meter bar at the bottom of the navbar isn’ it?
-
Ok no problem Sir
-
-
Add HTML Widget footer
<a id="btt" class=""><i class="fas fa-chevron-up"></i></a>
Did this solution help you?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (ether email, or push notification). You'll also be able to save bookmarks, use reactions, and upvote to show your appreciation to other community members.
With your input, this post could be even better 💗
RegisterLog in
1/7