Skip to content

Instantly share code, notes, and snippets.

@timeglider
Created October 26, 2011 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timeglider/1316914 to your computer and use it in GitHub Desktop.
Save timeglider/1316914 to your computer and use it in GitHub Desktop.
a jquery plugin to set Golden Section proportions on HTML box elements
$.fn.golden = function(options) {
var gold = 1.6180339,
wid, hei, neu, $elem,
defaults = {
adjust:"height", // height || width
orientation:"horiz" // horiz || vert
},
opt = $.extend(defaults, options);
return this.each (function() {
$elem = $(this);
if (opt.adjust === "height") {
// width is set by user; adjust height
wid = $elem.width();
if (opt.orientation === "vert") {
neu = wid * gold; // i.e. larger
$elem.css({"height":neu});
} else {
neu = wid / gold; // i.e. smaller
$elem.css({"height":neu});
}
} else {
// height set by user; adjust width
hei = $elem.height();
if (opt.orientation === "horiz") {
neu = hei * gold; // i.e. larger
$elem.css({"width":neu});
} else {
neu = hei / gold; // i.e. smaller
$elem.css({"width":neu});
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment