Progress Bar in Jquery

Asked

Viewed 1,011 times

0

Guys, I have a bar that works as follows, when my scroll is on top of the div of the bars they will start to fill. I made the css, but I’m not able to do Jquery, some hint?

HTML:

    <label for="barra"><h2>HTML </h2><span id="porcentagemhtml"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

    <label for="barra"><h2>CSS </h2><span id="porcentagecss"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

    <label for="barra"><h2>JAVASCRIPT </h2><span id="porcentagemjs"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

    <label for="barra"><h2>PHP </h2><span id="porcentagemphp"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

    <label for="barra"><h2>SQL </h2><span id="porcentagemsql"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

CSS:

.container-barra{
  width: 100%;
  border: 0.1px solid;
  border-radius: 15px;
}

.barra{
  width: 0%;
  height: 20px;
  background-color: black;
  border-radius: 15px;

}

jquery:

$(document).scroll(function(){      
   var posicao = window.pageYOffset;
   if(posicao>=1287){
     setInterval(encheBarra, 30);
   } 
});
// Chamada da Função
function encheBarra(){

}

1 answer

1


function move(idElem) {
  var elem = document.getElementById(idElem); 
  var width = 0;
  var id = setInterval(frame, 10);
  function frame() {
    if (width >= 100) {
      clearInterval(id);
    } else {
      width++; 
      elem.style.width = width + '%'; 
    }
  }
}
var auxPhp = 0;
var auxSql = 0;

$(window).on('scroll', function(){
    if(isScrolledIntoView('#barraPhp') && auxPhp == 0){
        move('barraPhp');
        auxPhp = 1;
    }
    if(isScrolledIntoView('#barraSql') && auxSql == 0){
        move('barraSql');
        auxSql = 1;
    }
});
function isScrolledIntoView(elem){
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
.container-barra{
  width: 100%;
  border: 0.1px solid;
  border-radius: 15px;
}

.barra{
  width: 0%;
  height: 20px;
  background-color: black;
  border-radius: 15px;

}
<label for="barra"><h2>HTML </h2><span id="porcentagemhtml"></span></label>
    <div class="container-barra">
      <div class="barra" id="barraHtml" ></div>
    </div>
    <button onclick="move('barraHtml')">Click Me</button> 

    <label for="barra"><h2>CSS </h2><span id="porcentagecss"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

    <label for="barra"><h2>JAVASCRIPT </h2><span id="porcentagemjs"></span></label>
    <div class="container-barra">
      <div class="barra"></div>
    </div>

    <label for="barra"><h2>PHP </h2><span id="porcentagemphp"></span></label>
    <div class="container-barra">
      <div class="barra" id="barraPhp"></div>
    </div>

    <label for="barra"><h2>SQL </h2><span id="porcentagemsql"></span></label>
    <div class="container-barra">
      <div class="barra" id="barraSql"></div>
    </div>
    
   
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

I made an example of how you could fill the bar, click the button Click Me to see the example working. I just don’t quite understand the scroll part, do you want those bars to be visible so that the user starts filling up? If yes, I did so for php and sql progress bars.

  • Yes, like, when I got to the 1287 position of the screen, the bar was full. I was able to do Javascript with w3c’s Ex, but not in Jquery

Browser other questions tagged

You are not signed in. Login or sign up in order to post.