{"id":9094,"date":"2021-10-30T00:47:19","date_gmt":"2021-10-29T21:47:19","guid":{"rendered":"https:\/\/elzero.org\/?p=9094"},"modified":"2022-09-28T18:21:39","modified_gmt":"2022-09-28T15:21:39","slug":"tutorials-increase-numbers-on-scrolling","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-increase-numbers-on-scrolling\/","title":{"rendered":"Increase Numbers On Scrolling"},"content":{"rendered":"<h3>\u0627\u0644 Code<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-html\">\r\n<section class=\"one\">Section One<\/section>\r\n<section class=\"two\">Section Two<\/section>\r\n<section class=\"three\">\r\n  <div class=\"nums\">\r\n    <div class=\"num\" data-goal=\"100\">0<\/div>\r\n    <div class=\"num\" data-goal=\"500\">0<\/div>\r\n    <div class=\"num\" data-goal=\"300\">0<\/div>\r\n  <\/div>\r\n<\/section>\r\n<section class=\"four\">Section Four<\/section>\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-css\">\r\n* {\r\n  box-sizing: border-box;\r\n}\r\nbody {\r\n  font-family: \"Trebuchet MS\", \"Lucida Sans Unicode\", sans-serif;\r\n  margin: 0;\r\n}\r\nsection {\r\n  min-height: 100vh;\r\n  display: flex;\r\n  justify-content: center;\r\n  align-items: center;\r\n}\r\nsection:first-child {\r\n  background-color: #aaa;\r\n}\r\nsection:nth-child(2) {\r\n  background-color: #bbb;\r\n}\r\nsection:nth-child(3) {\r\n  background-color: #ccc;\r\n}\r\nsection:last-of-type {\r\n  background-color: #eee;\r\n}\r\n.nums {\r\n  width: 400px;\r\n  display: flex;\r\n}\r\n.nums .num {\r\n  flex: 1;\r\n  text-align: center;\r\n  font-size: 40px;\r\n  padding: 20px;\r\n}\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nlet nums = document.querySelectorAll(\".nums .num\");\r\nlet section = document.querySelector(\".three\");\r\nlet started = false; \/\/ Function Started ? No\r\n\r\nwindow.onscroll = function () {\r\n  if (window.scrollY >= section.offsetTop) {\r\n    if (!started) {\r\n      nums.forEach((num) => startCount(num));\r\n    }\r\n    started = true;\r\n  }\r\n};\r\n\r\nfunction startCount(el) {\r\n  let goal = el.dataset.goal;\r\n  let count = setInterval(() => {\r\n    el.textContent++;\r\n    if (el.textContent == goal) {\r\n      clearInterval(count);\r\n    }\r\n  }, 2000 \/ goal);\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644 Code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[879],"tags":[],"class_list":["post-9094","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=9094"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9094\/revisions"}],"predecessor-version":[{"id":9096,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9094\/revisions\/9096"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=9094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=9094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=9094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}