Reputation: 37
I have a function, that center some elements on page. But it not working on page first time load. It calls after page reload. How to fix it?
jQuery.fn.positionCenter = function() {
this.css("position", "absolute");
this.css("top", ($(window).height() / 2) - (this.outerHeight() / 2));
this.css("left", ($(window).width() / 2) - (this.outerWidth() / 2));
return this;
}
$(".play_btn, .around").positionCenter();
$(window).resize(function(){
$(".play_btn, .around").positionCenter();
});
Upvotes: 0
Views: 88
Reputation: 152216
Try with binding also the document.ready
event:
$(document).ready(function(){
$(".play_btn, .around").positionCenter();
});
$(window).resize(function(){
$(".play_btn, .around").positionCenter();
});
Upvotes: 2