Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

backToTop - moved to app js

DanielŻuławski5e4c71187c29
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/app.js b/src/Web/Grand.Web/wwwroot/theme/script/app.js
index 9a091261a..5d203ff5a 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/app.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/app.js
@@ -32,6 +32,7 @@
if (localStorage.fluid == "") this.fluid = "false";
if (localStorage.darkMode == "true") this.darkMode = true;
this.updateCompareProductsQty();
+ this.backToTop();
},
watch: {
fluid: function (newName) {
@@ -45,6 +46,35 @@
}
},
methods: {
+ backToTop() {
+ if (!document.querySelector('.up-btn')) {
+ const upBtn = document.createElement('div');
+ const upBtnContent = document.createElement('div');
+
+ upBtn.classList.add('up-btn', 'up-btn__hide');
+
+ function showBtn(num) {
+ if (document.documentElement.scrollTop >= num) {
+ upBtn.classList.remove('up-btn__hide');
+ } else {
+ upBtn.classList.add('up-btn__hide');
+ }
+ }
+
+ document.body.append(upBtn);
+ upBtn.append(upBtnContent)
+ window.addEventListener('scroll', () => {
+ showBtn(400);
+ });
+
+ upBtn.addEventListener('click', () => {
+ window.scrollTo({
+ top: 0,
+ behavior: "smooth"
+ });
+ });
+ }
+ },
newsletterBox(AllowToUnsubscribe, url) {
let subscribe;
if (AllowToUnsubscribe) {
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
index 1a20e2dd8..02b9323b1 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
@@ -142,40 +142,6 @@ function StopPropagation(event) {
event.stopPropagation();
}
-function backToTop() {
- if (!document.querySelector('.up-btn')) {
- const upBtn = document.createElement('div');
- const upBtnContent = document.createElement('div');
-
- upBtn.classList.add('up-btn', 'up-btn__hide');
-
- function showBtn(num) {
- if (document.documentElement.scrollTop >= num) {
- upBtn.classList.remove('up-btn__hide');
- } else {
- upBtn.classList.add('up-btn__hide');
- }
- }
-
- document.body.append(upBtn);
- upBtn.append(upBtnContent)
- window.addEventListener('scroll', () => {
- showBtn(400);
- });
-
- upBtn.addEventListener('click', () => {
- window.scrollTo({
- top: 0,
- behavior: "smooth"
- });
- });
- }
-}
-
-document.addEventListener("DOMContentLoaded", function () {
- backToTop();
-});
-
/* MENU */
(function () {
function $(selector, context) {