Skip to main content

How to add horizontality progress bar on vertical scroll in jQuery?

Add horizontality progress bar on vertical scroll in jQuery


 <div id="scrollBar"></div> 

<div class="on_scroll_bx"></div> 

<script>

(function($) {

    $(document).ready(function(){

        var winHeight = $(window).height();

        var $scrollBar = $('#scrollBar');

        //var $progressLabel = $('.et-progress-label p span');   

        var $postContent = $('.on_scroll_bx');

        $scrollBar.css('width', 0);

       // $progressLabel.html('0%');

        

        $(window).scroll(function(){

            var postContentHeight = $postContent.height();          

            var postContentStartPosition = $postContent.offset().top;

            var winScrollTop = $(window).scrollTop();

            var postScrollTop = postContentStartPosition - winScrollTop;

            var postScrollableArea = postContentHeight - winHeight;

            var postScrollPercentage = Math.abs((postScrollTop/postScrollableArea)*100);

            if (postScrollTop > 0) {

                $scrollBar.css('width', 0);

               // $progressLabel.html('0%');

            } else if (postScrollTop < 0 && postScrollTop > -postScrollableArea) {

                $scrollBar.css('width', (postScrollPercentage + '%'));

              //  $progressLabel.html( Math.round(postScrollPercentage) + '%');

            } else if (postScrollTop < -postScrollableArea) {

                $scrollBar.css('width', '100' + '%');

               // $progressLabel.html('100%');

            }

        });

    });

})( jQuery );

</script>    

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...