Created
April 12, 2012 06:06
-
-
Save hirotaka11/2364893 to your computer and use it in GitHub Desktop.
jQuery .hover のツールチップ関数化
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
// こんなHTMLファイルがあって、imgのhoverで div.cnt を表示したい | |
/* | |
<div class="wrap"> | |
<img class="ico" src="" /> | |
<div class="cnt"> | |
//表示したい項目 | |
</div> | |
</div> | |
*/ | |
j$(document).ready(function(){ | |
/* | |
これだと出来る | |
j$(".ico").hover( | |
function() { | |
j$(this).siblings(".cnt").animate({opacity: 1}, 300); | |
}, | |
function() { | |
j$(this).siblings(".cnt").animate({opacity: 0}, 300); | |
} | |
) | |
*/ | |
// こんな感じで関数化 | |
// パターン1 | |
var open = function(cls) { | |
j$(cls).animate({opacity: 1}, 300); | |
}; | |
var close = function(cls) { | |
j$(cls).animate({opacity: 0}, 300); | |
}; | |
j$(".ico").hover(function() { | |
var cnt = j$(this).siblings('.cnt'); | |
open(cnt); | |
}, function() { | |
var cnt = j$(this).siblings('.cnt'); | |
close(cnt); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment