(function($) {
jQuery.fn.center = function () {
this.css('position','absolute');
this.css('top', ( $(window).height() - this.height() ) /2 +$(window).scrollTop() + 'px');
this.css('left', ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + 'px');
return this;
}
$("#bannerBar").center();
$('#banner').mousedown( function (event) {
var isMove = true;
var abs_x = event.pageX - $('#bannerBar').offset().left;
var abs_y = event.pageY - $('#bannerBar').offset().top;
$(document).mousemove(function (event) {
if (isMove) {
var obj = $('#bannerBar');
obj.css({'left':event.pageX - abs_x, 'top':event.pageY - abs_y});
}
}).mouseup(function () {
isMove = false;
});
});
})(jQuery);
html中div居中并移动
最新推荐文章于 2023-05-30 17:47:00 发布