Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created October 30, 2011 04:54
Show Gist options
  • Save nissuk/1325516 to your computer and use it in GitHub Desktop.
Save nissuk/1325516 to your computer and use it in GitHub Desktop.
jQuery: hoverOpacity
/**
* jQuery hoverOpacity
* hoverしたときにopacityを指定値まで段階的に変化させ、カーソルが離れたら1まで戻します。
*
* # 使用例
* $("a:has(img)").hoverOpacity(0.5);
*/
(function($) {
var pluginName = "hoverOpacity";
var plugin = function(value, options) {
var settings = $.extend({}, plugin.defaults, options);
return this.hover(
function(){ $(this).stop(true).animate({ opacity: value }, settings) },
function(){ $(this).stop(true).animate({ opacity: 1 }, settings) }
);
};
plugin.defaults = { duration: "fast" };
$.fn[pluginName] = plugin;
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment