💄 Add tool button click events make it more silky.

This commit is contained in:
凡梦星尘 2022-10-06 10:48:52 +08:00
parent 0abad2539a
commit 0536ac37fc
3 changed files with 27 additions and 4 deletions

View File

@ -10,6 +10,7 @@ NexT.boot.registerEvents = function() {
NexT.utils.registerScrollPercent();
// NexT.utils.registerCanIUseTag();
NexT.utils.registerToolButtons();
// Mobile top menu bar.
document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => {

View File

@ -23,6 +23,28 @@ HTMLElement.prototype.wrap = function(wrapper) {
NexT.utils = {
registerToolButtons: function() {
const comms_offset = document.getElementById('comments').getBoundingClientRect().top + window.scrollY;
document.getElementById('goto-comments').addEventListener('click', () => {
window.anime({
targets : document.scrollingElement,
duration : 500,
easing : 'linear',
scrollTop: comms_offset
});
});
const gt_offset = document.getElementById('google_translate_element').getBoundingClientRect().top + window.scrollY;
document.getElementById('goto-gt').addEventListener('click', () => {
window.anime({
targets : document.scrollingElement,
duration : 500,
easing : 'linear',
scrollTop: gt_offset
});
});
},
regSwitchThemeBtn: function() {
const switchThemeBtn = document.getElementById('switch-theme');
if (!switchThemeBtn) return;

View File

@ -1,14 +1,14 @@
<div class="tool-buttons" >
<a id="goto-comments" class="button goto-comments" href="#comments" title="{{ T "ToolBtns.comment" }}">
<div id="goto-comments" class="button goto-comments" title="{{ T "ToolBtns.comment" }}">
<i class="fas fa-comments"></i>
</a>
</div>
<div id="switch-theme" class="button" title="{{ T "ToolBtns.theme" }}">
<i class="fas fa-adjust"></i>
</div>
{{ if .Site.Params.footer.translate }}
<a class="button" href="#google_translate_element" title="{{ T "ToolBtns.lang" }}">
<div id="goto-gt" class="button" title="{{ T "ToolBtns.lang" }}">
<i class="fas fa-globe"></i>
</a>
</div>
{{ end }}
{{- if and .Site.Params.backTop.enable (not .Site.Params.backTop.sidebar) }}
<div class="back-to-top" role="button" title="{{ T "ToolBtns.backTop" }}">