Created
February 23, 2012 21:59
-
-
Save jescalan/1895286 to your computer and use it in GitHub Desktop.
imgfade
This file contains hidden or 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.imgFade = (time) -> | |
| # set default time | |
| time ?= 500 | |
| # wrap it | |
| this.wrap("<div class='#{this.attr('class')}' />") | |
| wrapper = | |
| this | |
| .parent() | |
| .css({ 'background-image': 'none', position: 'relative' }) | |
| this.css({ margin: 0, padding: 0, position: 'absolute', top: 0, left: 0 }) | |
| hover_state = | |
| this | |
| .clone() | |
| .css({ margin: 0, padding: 0, position: 'absolute', top: 0, left: 0, opacity: 0, 'background-position': "0 -#{this.height()}px" }) | |
| .appendTo(wrapper) | |
| wrapper.hover => | |
| this.stop(true, false).delay(time/2).animate({ opacity: 0 }, time) | |
| hover_state.stop(true, false).animate({ opacity: 1 }, time) | |
| , => | |
| this.stop(true, false).animate({ opacity: 1 }, time) | |
| hover_state.stop(true, false).delay(time/2).animate({ opacity: 0 }, time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment