From d318faca2ca4d2c16eb5c839cf4ec519b3d7e9f6 Mon Sep 17 00:00:00 2001 From: troy Date: Mon, 14 Feb 2022 12:23:22 +0100 Subject: [PATCH] backtotop --- README.md | 13 ++++++++++--- backtotop.css | 24 ++++++++++++++++++++++++ backtotop.js | 31 +++++++++++++++++++++++++++++++ backtotop.min.css | 1 + backtotop.min.js | 2 ++ backtotop.min.js.map | 33 +++++++++++++++++++++++++++++++++ feedback.js | 7 +++---- 7 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 backtotop.css create mode 100644 backtotop.js create mode 100644 backtotop.min.css create mode 100644 backtotop.min.js create mode 100644 backtotop.min.js.map diff --git a/README.md b/README.md index 47d9f3e..d6c6994 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ git submodule add https://git.seemsleg.it/pub/cssjs-func-lib cssjs +``` diff --git a/backtotop.css b/backtotop.css new file mode 100644 index 0000000..7dd20f6 --- /dev/null +++ b/backtotop.css @@ -0,0 +1,24 @@ +#back_to_top { + position: fixed; + bottom: 40px; + right: 40px; + z-index: 9999; + width: 30px; + height: 30px; + text-align: center; + line-height: 30px; + background: #f5f5f5; + color: #444; + cursor: pointer; + border-radius: 15px; + padding-top: 4px; + display: none; + } + + #back_to_top:hover { + background: #e9ebec; + } + + #back_to_top.back_to_top-show { + display: block; + } \ No newline at end of file diff --git a/backtotop.js b/backtotop.js new file mode 100644 index 0000000..5a841ff --- /dev/null +++ b/backtotop.js @@ -0,0 +1,31 @@ +(function() { + 'use strict'; + + function trackScroll() { + var scrolled = window.pageYOffset; + var coords = document.documentElement.clientHeight; + console.log(coords,scrolled); + + if (scrolled > coords) { + goTopBtn.classList.add('back_to_top-show'); + } + if (scrolled < coords) { + goTopBtn.classList.remove('back_to_top-show'); + } + } + + function backToTop() { + if (window.pageYOffset > 0) { + window.scrollBy(0, -30); + setTimeout(backToTop, 0); + } + } + + var goTopBtn = document.createElement("div"); + goTopBtn.id = 'back_to_top'; + goTopBtn.innerHTML = 'UP'; + document.body.appendChild(goTopBtn); + + window.addEventListener('scroll', trackScroll); + goTopBtn.addEventListener('click', backToTop); +})(); \ No newline at end of file diff --git a/backtotop.min.css b/backtotop.min.css new file mode 100644 index 0000000..e4441b4 --- /dev/null +++ b/backtotop.min.css @@ -0,0 +1 @@ +#back_to_top{position:fixed;bottom:40px;right:40px;z-index:9999;width:30px;height:30px;text-align:center;line-height:30px;background:#f5f5f5;color:#444;cursor:pointer;border-radius:15px;padding-top:4px;display:none}#back_to_top:hover{background:#e9ebec}#back_to_top.back_to_top-show{display:block} \ No newline at end of file diff --git a/backtotop.min.js b/backtotop.min.js new file mode 100644 index 0000000..99dd846 --- /dev/null +++ b/backtotop.min.js @@ -0,0 +1,2 @@ +!function(){"use strict";function trackScroll(){var scrolled=window.pageYOffset,coords=document.documentElement.clientHeight;console.log(coords,scrolled),scrolled>coords&&goTopBtn.classList.add("back_to_top-show"),scrolled0&&(window.scrollBy(0,-30),setTimeout(backToTop,0))}var goTopBtn=document.createElement("div");goTopBtn.id="back_to_top",goTopBtn.innerHTML="UP",document.body.appendChild(goTopBtn),window.addEventListener("scroll",trackScroll),goTopBtn.addEventListener("click",backToTop)}(); +//# sourceMappingURL=backtotop.min.js.map \ No newline at end of file diff --git a/backtotop.min.js.map b/backtotop.min.js.map new file mode 100644 index 0000000..d50031b --- /dev/null +++ b/backtotop.min.js.map @@ -0,0 +1,33 @@ +{ + "version": 3, + "sources": [ + "backtotop.js" + ], + "names": [ + "trackScroll", + "scrolled", + "window", + "pageYOffset", + "coords", + "document", + "documentElement", + "clientHeight", + "console", + "log", + "goTopBtn", + "classList", + "add", + "remove", + "backToTop", + "scrollBy", + "setTimeout", + "createElement", + "id", + "innerHTML", + "body", + "appendChild", + "addEventListener" + ], + "mappings": "CAAA,WACE,aAEA,SAASA,cACP,IAAIC,SAAWC,OAAOC,YAClBC,OAASC,SAASC,gBAAgBC,aACtCC,QAAQC,IAAIL,OAAOH,UAEfA,SAAWG,QACbM,SAASC,UAAUC,IAAI,oBAErBX,SAAWG,QACbM,SAASC,UAAUE,OAAO,oBAI9B,SAASC,YACHZ,OAAOC,YAAc,IACvBD,OAAOa,SAAS,GAAI,IACpBC,WAAWF,UAAW,IAI1B,IAAIJ,SAAWL,SAASY,cAAc,OACtCP,SAASQ,GAAK,cACdR,SAASS,UAAY,KACrBd,SAASe,KAAKC,YAAYX,UAE1BR,OAAOoB,iBAAiB,SAAUtB,aAClCU,SAASY,iBAAiB,QAASR,WA7BrC", + "file": "backtotop.js" +} \ No newline at end of file diff --git a/feedback.js b/feedback.js index 4c074f0..5db212b 100644 --- a/feedback.js +++ b/feedback.js @@ -24,7 +24,6 @@ function ajaxFeedback(e,url,css) { function formFeedback(e,f,url,css) { var formData = {} - //TODO form erkennen und auslesen und disablen $(f).each(function(i, obj) { console.log(obj); formData[obj.name] = obj.value @@ -115,7 +114,7 @@ function successMarker(e,css) { var cursorX = p.x var cursorY = p.y console.log('OK',cursorX,cursorY); - + o = $('
'); $( "body" ).append( o ); $(o).fadeOut(5000); @@ -127,7 +126,7 @@ function warnMarker(e,css) { var cursorX = p.x var cursorY = p.y console.log('WARN',cursorX,cursorY); - + o = $('
'); $( "body" ).append( o ); $(o).fadeOut(5000); @@ -139,7 +138,7 @@ function errorMarker(e,css) { var cursorX = p.x var cursorY = p.y console.log('ERR',cursorX,cursorY); - + o = $('
'); $( "body" ).append( o ); $(o).fadeOut(5000);