{"id":3936,"date":"2023-06-18T11:36:28","date_gmt":"2023-06-18T09:36:28","guid":{"rendered":"https:\/\/www.knowboard.de\/?p=3936"},"modified":"2023-07-23T14:22:52","modified_gmt":"2023-07-23T12:22:52","slug":"scroll-depth-indicator","status":"publish","type":"post","link":"https:\/\/www.knowboard.de\/scroll-depth-indicator\/","title":{"rendered":"Scroll Depth Indicator"},"content":{"rendered":"\n
jQuery(function($) {\n\n $( document ).ready(function() {\n if ($('.animatedCounter').length) {\n $(window).scroll(testScroll);\n }\n });\n var viewed = false;\n\n function isScrolledIntoView(elem) {\n var docViewTop = $(window).scrollTop();\n var docViewBottom = docViewTop + $(window).height();\n\n var elemTop = $(elem).offset().top;\n var elemBottom = elemTop + $(elem).height();\n\n return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));\n }\n\n function testScroll() {\n if (isScrolledIntoView($(\".animatedCounter\")) && !viewed) {\n viewed = true;\n $('.animatedCounter').each(function () {\n $(this).prop('Counter',0).animate({\n Counter: $(this).text()\n }, {\n duration: 1000,\n easing: 'swing',\n step: function (now) {\n $(this).text(Math.ceil(now));\n }\n });\n });\n }\n }\n}(jQuery));<\/code><\/pre>\n\n\n\n