【发布时间】:2011-06-14 23:57:10
【问题描述】:
我正在尝试创建一个可以应用于 div 的函数,并让该 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)
});
【问题讨论】:
标签: jquery function center centering