Permalink
Browse files

basic plugin

  • Loading branch information...
0 parents commit 36378d1cb63d53f020e6f8f910041e5360b27a3e Will McNeilly committed Mar 24, 2012
Showing with 46 additions and 0 deletions.
  1. +46 −0 jquery.vHeight.js
46 jquery.vHeight.js
@@ -0,0 +1,46 @@
+/*!
+ * A Responsive Height plugin for jQuery v1.7
+ * @link
+ * @description Set a height in percentage on a container and have it
+ * increase/decrease with the size of the viewport.
+ * @author Will McNeilly <http://willmcneilly.com/>
+ */
+
+(function($,undefined){
+ $.fn.vHeight = function(params) {
+
+ var settings = $.extend(
+ {},
+ {
+ dataAttName : "vheight",
+ className : "vheight"
+ },
+ params);
+
+
+ vheightObjects = $.find('.' + settings.className);
+
+ getViewportHeight = function() {
+ viewportHeight = $(window).height();
+ return viewportHeight;
+ }
+
+ calcNewHeight = function( percentHeight, viewportHeightPixels) {
+ return (percentHeight / 100) * viewportHeightPixels;
+ }
+
+ setNewHeight = function() {
+ viewportHeight = getViewportHeight();
+ $(vheightObjects).each(function(){
+ percentHeight = $(this).data(settings.dataAttName);
+ newHeightInPixels = calcNewHeight(percentHeight, viewportHeight);
+ $(this).height(newHeightInPixels + 'px');
+ });
+ }
+
+ $(window).bind("load resize", function(){
+ setNewHeight();
+ });
+
+ }
+})(jQuery);

0 comments on commit 36378d1

Please sign in to comment.