Skip to content

Instantly share code, notes, and snippets.

@Partoo
Created June 30, 2013 03:40
Show Gist options
  • Select an option

  • Save Partoo/5893747 to your computer and use it in GitHub Desktop.

Select an option

Save Partoo/5893747 to your computer and use it in GitHub Desktop.
Some common code.
//Highlight current category
$(function () {
var url = window.location.pathname,
re = /^\/\w*/;
urlRegExp=url.match(re);
urlRe = new RegExp(url.replace( /^\/\w*/));
$('ul.mainNav>li >a').each(function(){
if ($(this).attr('href').match(re).toString()==url.match(re).toString()) {
$(this).parent("li").addClass('current');
}
});
//Show banner random
$('.mainNav li').hover(function () {$('ul', this).show();},function () {$('ul', this).hide();});
var img = new Image();
var num = Math.floor(Math.random() * 6+1);
$(img).load(function() {
$(this).hide();
$(".banner").removeClass("loading").append(this);
$(this).show();
}).attr('src','/images/banner'+num+'.jpg');
// Navbar hover effects (for IE li:hover bug)
$('.mainNav>li').hover(function(){
$(this).addClass('hoverCss');
},function(){
$(this).removeClass('hoverCss');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment