{"id":9091,"date":"2021-10-27T23:15:35","date_gmt":"2021-10-27T20:15:35","guid":{"rendered":"https:\/\/elzero.org\/?p=9091"},"modified":"2022-09-28T18:21:49","modified_gmt":"2022-09-28T15:21:49","slug":"tutorials-animate-width-on-scrolling","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-animate-width-on-scrolling\/","title":{"rendered":"Animate Width 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=\"skills\">\r\n    <h3>HTML<\/h3>\r\n    <div class=\"progress\">\r\n      <span style=\"width: 0\" data-width=\"80%\"><\/span>\r\n    <\/div>\r\n    <h3>CSS<\/h3>\r\n    <div class=\"progress\">\r\n      <span style=\"width: 0\" data-width=\"90%\"><\/span>\r\n    <\/div>\r\n    <h3>Scala<\/h3>\r\n    <div class=\"progress\">\r\n      <span style=\"width: 0\" data-width=\"50%\"><\/span>\r\n    <\/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.progress {\r\n  position: relative;\r\n  width: 500px;\r\n  height: 30px;\r\n  background-color: white;\r\n  margin: 10px;\r\n}\r\n.progress span {\r\n  position: absolute;\r\n  left: 0;\r\n  top: 0;\r\n  height: 100%;\r\n  background-color: indianred;\r\n  transition: width 0.3s linear;\r\n}\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nlet section = document.querySelector(\".three\");\r\nlet spans = document.querySelectorAll(\".progress span\");\r\n\r\nwindow.onscroll = function () {\r\n  if (window.scrollY >= section.offsetTop) {\r\n    console.log(\"Reached Section Three\");\r\n    spans.forEach((span) => {\r\n      span.style.width = span.dataset.width;\r\n    });\r\n  }\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-9091","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9091","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=9091"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9091\/revisions"}],"predecessor-version":[{"id":9092,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9091\/revisions\/9092"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=9091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=9091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=9091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}