top of page

Wix Studio Tips and Tricks

Public·1 member

How to create a Scroll Progress Bar in Wix Studio - Code

Code without percent value


<div id="progressBar">
  <div id="progress"></div>
</div>

<style>
  #progressBar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
    background-color: #ddd;
    z-index: 1000;
  }

  #progress {
    height: 100%;
    background-color: #4caf50;
    width: 0%;
  }
</style>

<script>
  document.addEventListener('scroll', function() {
    const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    const scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
    const scrolled = (scrollTop / scrollHeight) * 100;
    document.getElementById('progress').style.width = scrolled + '%';
  });
</script>

Code with a percent value



<div id="progressContainer">
  <div id="progressBar">
    <div id="progress">
      <span id="progressText">0%</span>
    </div>
  </div>
</div>

<style>
  #progressContainer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 10px;
    z-index: 1000;
    pointer-events: none; 
  }

  #progressBar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #ddd;
    border: 1px solid #333; 
    border-radius: 10px;
    overflow: hidden;
  }

  #progress {
    height: 100%;
    background-color: #4caf50;
    width: 0%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px; 
    border-radius: 8px; 
  }

  #progressText {
    position: relative;
    z-index: 1; 
    color: #fff; 
  }
</style>

<script>
  document.addEventListener('scroll', function() {
    const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    const scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
    const scrolled = (scrollTop / scrollHeight) * 100;
    document.getElementById('progress').style.width = scrolled + '%';
    document.getElementById('progressText').textContent = Math.round(scrolled) + '%';
  });
</script>

92 Views

About

Share your cool Wix Studio Tips and Tricks

bottom of page