Created
October 26, 2011 16:34
-
-
Save timeglider/1316914 to your computer and use it in GitHub Desktop.
a jquery plugin to set Golden Section proportions on HTML box elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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