本文主要是介绍原生js实现下滑到当前模块进度条填充,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<div style="height: 1500px;"></div>
<div class="progress-container"><div class="progress-bar" data-progress="90%"><p class="progress-text">Google Ads在Google搜索引擎上覆盖超过90%的互联网用户。</p></div><p class="progress-tag">90%</p><div class="progress-bar" data-progress="60%"><p class="progress-text">超过2/3的潜在用户会被精准定位的Google Ads付费广告所吸引,点进进入。</p></div><p class="progress-tag">2/3</p><div class="progress-bar" data-progress="90%"><p class="progress-text">覆盖全球超过200万个网站和应用,可触及到网上90%的互联网用户。</p></div><p class="progress-tag">200w+</p></div><style>.progress-container {margin: 50px 0;
}.progress-bar {width: 80%;height: 80px;background-color: #ffffff;border-radius: 5px;/* overflow: hidden; */position: relative;margin-bottom: 20px;display: inline-block;margin-right: 30px;
}.progress-bar::before {content: '';position: absolute;left: 0;top: 0;height: 100%;width: var(--progress-width, 0); /* 使用CSS变量 */background-color: #000000;transition: width 2s ease;border-radius: 5px 0 0 5px;
}
.progress-text{position: relative;z-index: 1;margin: 0;line-height: 30px;font-size: 16px;white-space: normal;color: #ffffff;width: 55%;text-align: left;margin-top: 10px;margin-left: 15px;
}
.progress-tag{width: 80px;height: 80px;padding: 20px;font-weight: 700;display: inline-block;margin: 0;border-radius: 50%;color: #ffffff;background-color: #000000;text-align: center;line-height: 40px;margin-bottom: 20px;
}@media screen and (max-width:768px) {.progress-container {margin: 50px 10px;}.progress-bar {width: 68%;margin-right: 20px;}.progress-text {line-height: 18px;font-size: 12px;width: 55%;}.google-six-content ul li h3 {width: 150px;height: 150px;line-height: 130px;}
}</style><script>
document.addEventListener('DOMContentLoaded', function() {var progressBars = document.querySelectorAll('.progress-bar');document.addEventListener('scroll', function() {var windowHeight = window.innerHeight;progressBars.forEach(function(bar) {var rect = bar.getBoundingClientRect();if (rect.top < windowHeight) {var progress = bar.getAttribute('data-progress');bar.style.setProperty('--progress-width', progress);}});});
});</script>
这篇关于原生js实现下滑到当前模块进度条填充的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!