divに適用できる関数を作成しようとしています。その関数を、垂直方向と水平方向の両方で、その親の中央に配置します。
センタリング機能を汎用化しようとしているので、センタリングコードを書き直し続ける必要はありません。
JQUERYを使用して、センタリングを最も簡単にするために何をしますか。
$('p').hoverIntent(function () {
var myObject = $('#bThis')
var Ctop = $(this).offset().top + ($(this).height() / 2) - (myObject.outerHeight() / 2)
var Cleft = $(this).offset().left + ($(this).width() / 2) - (myObject.outerWidth() / 2)
if ($('#placeB').hasClass('place')) {
$(this).animate({color: "#999999", backgroundColor: "#f5f5f5"}, 400)
$('#bThis').css({'left':Cleft, 'top':Ctop}).fadeIn(200)
}
}, function() {
$(this).stop().animate({color: "#333", backgroundColor: "#fff"}, 200)
$('#bThis').fadeOut(200)
});