Skip to content

Instantly share code, notes, and snippets.

@scottbaggett
Created October 25, 2012 00:16
Show Gist options
  • Select an option

  • Save scottbaggett/3949763 to your computer and use it in GitHub Desktop.

Select an option

Save scottbaggett/3949763 to your computer and use it in GitHub Desktop.
center items inside edge animation
// Add the 'center' class to any element you want to center on resize.
// Using this in combination with the scale-background mode will make backgrounds
// work on all sizes, Yay!
var $center_items = $(".center");
var center;
window.resize = function() {
console.log("resize");
$center_items.each(function(i,el){
center = $(window).width() / 2 - $(el).width() / 2;
console.log($(window).width());
$(el).css({
"left":center
});
});
}
$(window).resize(window.resize);
@jadonv
Copy link

jadonv commented Jul 19, 2013

hii.. uber noober here. I created a website. And i need the items centered.. accidently stumbled upon your code.. but no idea how to add these functions to the individual items..

i know you can add a general code with composition ready. but thats only for stage. do i add this in the actual .js files?

thanks in advance.

this is the site if your curious.
www.designwave.ca

@jadonv
Copy link

jadonv commented Jul 19, 2013

ok so i add the class i get that after reading it again.. where do i plug this code in tho?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment