2013-10-10 58 views
0

我正在使用fancybox 1.3.4在彈出窗口中顯示一些內容,但彈出窗口未在瀏覽器中居中如何解決它?fancybox不居中

的html代碼:

<a class="clickMe" title="" message="Last Updated: 10/1/2013">Privacy Policy</a> 

JS代碼:

$("body").on("click", ".clickMe", function(){ 
    showAlertSized($(this).attr("title"), $(this).attr("message"), $(this).attr("width"), $(this).attr("height")); 
}); 
function showAlertSized(title, msg, width, height) { 
    debugger; 
    if(width === undefined){ 
     //width = 965; 
     width = '95%'; 
    } 
    if(height === undefined) { 
     //height = 700; 
     height = '95%'; 
    } 
    var content = '<h1>' + title + '</h1>' + 
     '<p class="msg">' + msg + '</p>' + 
     '<div class="fancy-btns"><input type="button" value="" onclick="closeAlert()" class="fancy-ok-btn" /></div>'; 
    $.fancybox({ 
     'content': content, 
     'hideOnOverlayClick': false, 
     'overlayOpacity' : 0.7, 
     'overlayColor' : '#777', 
     'width': width, 
     'height': height, 
     'autoDimensions': false, 
     'autoSize': false 
    }); 
} 

這裏是截圖 enter image description here

+0

你的問題是什麼?我們在這裏看到的是一堆代碼和截圖... – Rohit

+0

請參閱問題的標題 – coure2011

回答

0

您的寬度和高度都通過邏輯分析,你設置視口的95%,因此有5%的寬度和高度不明。嘗試在您的fancybox初始化調用中添加「保證金」:2.5%,這應該會在您的fancybox的所有四面添加2.5%的保證金,使其完美居中。不幸的是我無法測試這個或提供一個編碼的例子,但理論上它應該工作!