簡體   English   中英

該功能不適用於首頁加載

[英]Function isn't working on first page load

我有一個功能,該功能將頁面上的某些元素居中。 但它不適用於第一次加載頁面。 頁面重新加載后調用。 如何解決?

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();
});

嘗試還綁定document.ready事件:

$(document).ready(function(){
    $(".play_btn, .around").positionCenter();
});

$(window).resize(function(){
    $(".play_btn, .around").positionCenter();
});

我解決了這個問題。 我在文件加載后調用功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM