Skip to content

Instantly share code, notes, and snippets.

@codesynapse
Created October 15, 2013 14:06
Show Gist options
  • Save codesynapse/6992114 to your computer and use it in GitHub Desktop.
Save codesynapse/6992114 to your computer and use it in GitHub Desktop.
Youtube/Medium.com LIke Progress Bar at Top on Genesis WordPress Theme
//code you need to add to functions.php file for adding JS file in js directory
add_action( 'wp_enqueue_scripts', 'gen_progressbar');
function gen_progressbar() {
wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri() . '/js/gen-progress.js', array( 'jquery' ) );
}
jQuery(document).ready(function($){
document.body.innerHTML+="<div id=\"progress\"><dt></dt><dd></dd></div>";
var pr=document.querySelector("#progress");
setTimeout(function(){
pr.style.width="60%";
},300);
setTimeout(function(){
pr.style.width="101%";
},800);
setTimeout(function(){
pr.parentNode.removeChild(pr);
},1600);
return false;
$(document).ajaxStart(function() {
//only add progress bar if added yet.
if ($("#progress").length === 0) {
$("body").append($("<div><dt/><dd/></div>").attr("id", "progress"));
$("#progress").width((50 + Math.random() * 30) + "%");
}
});
$(document).ajaxComplete(function() {
//End loading animation
$("#progress").width("101%").delay(200).fadeOut(400, function() {
$(this).remove();
});
});
});
#progress {
position: fixed;
z-index: 2147483647;
top: 0;
left: -6px;
width: 1%;
height: 2px;
background: #8a1c1f;
-moz-border-radius: 1px;
-webkit-border-radius: 1px;
border-radius: 1px;
-moz-transition: width 500ms ease-out,opacity 400ms linear;
-ms-transition: width 500ms ease-out,opacity 400ms linear;
-o-transition: width 500ms ease-out,opacity 400ms linear;
-webkit-transition: width 500ms ease-out,opacity 400ms linear;
transition: width 500ms ease-out,opacity 400ms linear;
}
#progress dd, #progress dt {
position: absolute;
top: 0;
height: 2px;
-moz-box-shadow: #8a1c1f 1px 0 6px 1px;
-ms-box-shadow: #8a1c1f 1px 0 6px 1px;
-webkit-box-shadow: #8a1c1f 1px 0 6px 1px;
box-shadow: #8a1c1f 1px 0 6px 1px;
-moz-border-radius: 100%;
-webkit-border-radius: 100%;
border-radius: 100%;
}
#progress dt {
opacity: .6;
width: 180px;
right: -80px;
clip: rect(-6px,90px,14px,-6px);
}
#progress dd {
opacity: .6;
width: 20px;
right: 0;
clip: rect(-6px,22px,14px,10px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment