An easy way to position and size a 'hero unit' for the plethora of devices we web developers need to support these days. Used in production at Artsy http://artsy.net/design-miami
jQuery.herounit ensures that your image will not be distorted while being vertically centered and flush to the edges of its container.
See this example using Placekitten
Download the production version (2.6kb) or the development version.
Include required Javascripts
<script src="jquery.js"></script>
<script src="dist/herounit.min.js"></script>
Create html like this
<div id="hero_unit">
<img src="heroic/img.jpg" />
</div>
Apply the herounit plugin
$('#hero_unit').herounit({
'height': 400,
'$img' : $('#hero_unit img')
});
Contributions and pull requests are very welcome. Please follow these guidelines when submitting new code.
- Fork and clone the repo.
- If needed:
npm install -g grunt
for Grunt - If needed:
brew install phantomjs
for PhantomJS - Run
npm install
to install dependencies - Run
grunt
(compiles coffeescripts and runs tests) - Run
grunt watch
while editing files to auto-compile coffeescripts and run tests - Make all changes in Coffeescript files, not JavaScript files.
- Add tests for the change you want to make. Run
grunt jasmine
to see if tests fail. - Run
grunt
to compile new dist and make sure nothing is broken - Submit a Pull Request using GitHub.