2011-07-08 16 views
1

更新與全彈出代碼問題的中心我的彈出

//SETTING UP OUR POPUP 
//0 means disabled; 1 means enabled; 
var cid; 
var hname; 
var cname; 
var cfname; 
var ctstamp; 

var popupCompareStatus = 0; 

//loading popup with jQuery magic! 
function loadComparePopup(){ 
//loads popup only if it is disabled 
if(popupCompareStatus==0){ 
    $("#compareBackgroundPopup").css({ 
     "opacity": "0.7" 
    }); 
    $("#compareBackgroundPopup").fadeIn("slow"); 
    $("#popupCompare").fadeIn("slow"); 
    popupCompareStatus = 1; 
} 
} 

//disabling popup with jQuery magic! 
function disableComparePopup(){ 
//disables popup only if it is enabled 
if(popupCompareStatus==1){ 
    $("#compareBackgroundPopup").fadeOut("slow"); 
    $("#popupCompare").fadeOut("slow"); 
    popupCompareStatus = 0; 
} 
} 

//centering popup 
function centerComparePopup(){ 
//request data for centering 
var windowWidth = document.documentElement.clientWidth; 
var windowHeight = document.documentElement.clientHeight; 
var popupHeight = $("#popupCompare").height(); 
var popupWidth = $("#popupCompare").width(); 
console.info("windowWidth="+windowWidth+", windowHeight="+windowHeight+"popupWidth="+popupWidth+", popupHeight="+popupHeight); 


$("#popupCompare").css({ 
    position: "absolute", 
    width: "800px", 
    top: $(window).height()/2 - $("#popupCompare").outerHeight()/2, 
    left: $(window).width()/2 - $("#popupCompare").outerWidth()/2 
}); 

$("#compareBackgroundPopup").css("height", $(window).height()); 
} 
var dummy1='<list> <TagResult elementname="osname" subCategory="system" value1="Linux" value2="HP-US1000" isEqual="false"/> <TagResult elementname="hostname" subCategory="system" value1="estilo" value2="benz" isEqual="false"/> <TagResult elementname="release" subCategory="system" value1="2.6.18-128.el5" value2="B.11.23" isEqual="false"/><TagResult elementname="version" subCategory="system" value1="Red Hat Enterprise Linux Server release 5.3 (Tikanga)" value2="U" isEqual="false"/> <TagResult elementname="machine" subCategory="system" value1="x86_64" value2="ia64 hp server rx2600" isEqual="false"/> <TagResult elementname="bitmode" subCategory="system" value1="64" value2="64" isEqual="true"/> <TagResult elementname="numberofcpu" subCategory="system" value1="4" value2="2" isEqual="false"/> <TagResult elementname="cpuspeed" subCategory="system" value1=" 1862.890" value2="1400" isEqual="false"/> <TagResult elementname="maxfilesperproc" subCategory="system" value1="32" value2=" 32" isEqual="true"/> <TagResult elementname="maxthreadsperproc" subCategory="system" value1="2000000" value2="     256 " isEqual="false"/><TagResult elementname="mempagesize" subCategory="system" value1="4096" value2="4096" isEqual="true"/><TagResult elementname="ssaname3webserviceserver" subCategory="product" value1="ssasvck&gt; Attempt 1 at server &apos;null:-1&apos;ssasvck&gt; Server&apos;null:-1&apos; is down" value2="ssasvck&gt; Attempt 1 at server &apos;null:-1&apos;ssasvck&gt; Server &apos;null:-1&apos; is down" isEqual="true"/><TagResult elementname="TERM" subCategory="envVariable" value1="xterm " value2="xterm" isEqual="true"/><TagResult elementname="JAVA_HOME" subCategory="envVariable" value1="/home/hqusers1/IIR_1152825121_estilo_9.0.1SP2_32 " isEqual="false"/><TagResult elementname="SSANUL" subCategory="envVariable" value1="/dev/null " value2="/dev/null" isEqual="true"/><TagResult elementname="SSA_LIHOST" subCategory="envVariable" value1="estilo:45682 " value2="benz:7660" isEqual="false"/><TagResult elementname="SSH_CLIENT" subCategory="envVariable" value1="10.65.6.131 4760 22 " value2="10.65.241.204 367222" isEqual="false"/></list>'; 

$('#compareTable a').live('click', function() { 
var elementId=$(this).attr("id"); 
showHiddenTr(elementId); 
}); 
function showHiddenTr(eid) 
{ 
if($(".differentEnvironmentHiddentr").is(':visible')) 
{ 
    $(".differentEnvironmentHiddentr").hide(); 
} 
else 
{ 
    $(".differentEnvironmentHiddentr").show(); 
}   
} 


function populateCompare(cmp) 
{ 
var mytr = new Array(); 
var mytrs=""; 
var i=0; 
var xml=dummy1; 
$('#compareContent').empty(); 
$('#compareContent').html("<table width='100%'><tbody><tr><td align='center'>Compare details being loaded</td></tr><tr><td align='center'><img src='/csm/view/include/images/loading.gif' alt='Loading'/></td></tr></tbody></table>"); 
if(cmp=="all") 
{ 

    $(xml).find('TagResult').each(function(){ 
     if($(this).attr("isEqual")=="false") 
     { 
      mytr[i]='<tr class="regulartr">'+ 
      '<td class="different" align="left">'+$(this).attr("elementname")+'</td>'+ 
      '<td class="different" align="left">'+$(this).attr("value1")+'</td>'+ 
      '<td class="different" align="left">'+$(this).attr("value2")+'</td>'+ 
      '</tr>'; 
      mytrs+=mytr[i++]; 
     } 
     else 
     { 
      mytr[i]='<tr class="regulartr">'+ 
      '<td class="nametd" align="left">'+$(this).attr("elementname")+'</td>'+ 
      '<td class="value1td" align="left">'+$(this).attr("value1")+'</td>'+ 
      '<td class="value2td" align="left">'+$(this).attr("value2")+'</td>'+ 
      '</tr>'; 
      mytrs+=mytr[i++]; 
     } 

    }); 


    $('#compareContent').empty(); 
    $('<div>') 
    .html('<table id="compareTable" cellspacing="0" cellpadding="0">'+ 
      '<thead><tr class="regulartr">'+ 
       '<th align="center">Name</th>'+ 
       '<th align="center">Config1</th>'+ 
       '<th align="center">Config2</th>'+ 
      '</tr></thead><tbody>'+mytrs 

     +'</tbody></table>') 
    .appendTo('#compareContent'); 

} 
if(cmp=="diff") 
{ 
    var env=0; 
    $(xml).find('TagResult').each(function(){ 

     if($(this).attr("isEqual")=="false") 
     { 
      if($(this).attr("subCategory")=="envVariable") 
      { 
       if(env==0) 
       { 
        mytr[i]='<tr class="regulartr">'+ 
        '<td class="different" align="left"><a id="showCmpEnvironment"><img src="http://pslxcsm01:8080/informaticaCSM/zkau/web/zul/img/tree/close.png"/>'+$(this).attr("subCategory")+'</a></td>'+ 
        '<td class="different" align="left"></td>'+ 
        '<td class="different" align="left"></td>'+ 
        '</tr>'; 
        mytrs+=mytr[i++]; 
        mytr[i]='<tr class="differentEnvironmentHiddentr">'+ 
        '<td class="different" align="left">&nbsp;&nbsp;'+$(this).attr("elementname")+'</td>'+ 
        '<td class="different" align="left">'+$(this).attr("value1")+'</td>'+ 
        '<td class="different" align="left">'+$(this).attr("value2")+'</td>'+ 
        '</tr>'; 
        mytrs+=mytr[i++]; 
        env=1; 
       } 
       else 
       { 


        mytr[i]='<tr class="differentEnvironmentHiddentr">'+ 
        '<td class="different" align="left">&nbsp;&nbsp;'+$(this).attr("elementname")+'</td>'+ 
        '<td class="different" align="left">'+$(this).attr("value1")+'</td>'+ 
        '<td class="different" align="left">'+$(this).attr("value2")+'</td>'+ 
        '</tr>'; 
        mytrs+=mytr[i++]; 
       } 
      } 
      else 
      { 
       mytr[i]='<tr class="regulartr">'+ 
       '<td class="different" align="left">'+$(this).attr("elementname")+'</td>'+ 
       '<td class="different" align="left">'+$(this).attr("value1")+'</td>'+ 
       '<td class="different" align="left">'+$(this).attr("value2")+'</td>'+ 
       '</tr>'; 
       mytrs+=mytr[i++]; 
      } 



     } 


    }); 


    $('#compareContent').empty(); 
    $('<div>') 
    .html('<table id="compareTable" cellspacing="0" cellpadding="0">'+ 
      '<thead><tr class="regulartr">'+ 
       '<th align="center">Name</th>'+ 
       '<th align="center">Config1</th>'+ 
       '<th align="center">Config2</th>'+ 
      '</tr></thead><tbody>'+mytrs 

     +'</tbody></table>') 
    .appendTo('#compareContent'); 

} 
} 



//CONTROLLING EVENTS IN jQuery 
$(document).ready(function(){ 

//LOADING POPUP 

$("#btnCompare").click(function(event){ 
    var count=getCheckedCount();  
    if(count==2) 
    { 
     //show compare 
     populateCompare("all"); 
     //centering with css 
     centerComparePopup(); 
     //load popup 
     loadComparePopup(); 
     //get configs 



    } 
    else if(count>2) 
    { 
     $("#messageBox").empty(); 
     $('<b>') 
     .html('To compare select only two configurations')  
     .appendTo('#messageBox'); 

     $("#messageBox").fadeIn().delay(2000).fadeOut('slow'); 
    }   
    else 
    { 
     $("#messageBox").empty(); 
     $('<b>') 
     .html('Please select two configurations to compare')   
     .appendTo('#messageBox'); 

     $("#messageBox").fadeIn().delay(2000).fadeOut('slow'); 
    }  
}); 

$('#compareForm input:radio').click(function() { 
     populateCompare($(this).val()); 
    }); 

//CLOSING POPUP 
//Click the x event! 
$("#popupCompareClose").click(function(){ 
    disableComparePopup(); 
}); 
//Click out event! 
$("#compareBackgroundPopup").click(function(){ 
    disableComparePopup(); 
}); 
//Press Escape event! 
$(document).keypress(function(e){ 
    if(e.keyCode==27 && popupCompareStatus==1){ 
     disableComparePopup(); 
    } 
}); 

}); 

enter image description here

下面是截圖你問

enter image description here

+1

莫不是,目前尚未加載彈出,這將是伸展的框意外維度內的內容?另一件我想嘗試的是在你的css文件中設置#popupCompare的寬度,如果總是相同的話,從你的函數中刪除寬度:80%。希望這可以幫助... –

+0

最新的問題,我可以從它的太小 –

+0

閱讀高度和寬度的東西@John:我將80%'改爲800px',但它仍然不工作..我認爲你是正確的,因爲它將xml數據加載到該彈出窗口中,所以如何修復彈出窗口的大小?我正在加載數據1st,然後居中它 – abi1964

回答

2

是有內部彈出任何圖像,調整大小彈出寬度會導致在圖像的尺寸調整後的寬度和最終尺寸調整的圖像高度

----- ----編輯

一兩件事你可以做添加此CSS彈出

.myPopUp 
{ 
height: whatever_you_like; 
overflow-y: auto; 
} 

現在如果高度超過高度的滾動會ppear,我希望這可以解決issua

+0

否沒有圖像 – abi1964

+0

你可以把一個大的圖像的屏幕截圖或放大一個 –

+0

我把一個應用程序屏幕截圖 – abi1964

1

我想,你應該添加獲取其高度和寬度之前,#popupCompare的CSS樣式。

0

試試這個:

$("#popupCompare").css({ 
    position: "absolute", 
    width: "80%", 
    top: $(window).height()/2 - $("#popupCompare").outerHeight()/2, 
    left: $(window).width()/2 - $("#popupCompare").outerWidth()/2 
}); 

$("#compareBackgroundPopup").css("height", $(window).height()); 
0

阿布舍克,

這就是我正在做的模態的中心位置在我的應用程序:

這將處理即使在滾動位置的窗口。

var winW = $(document).width(); 
if (winW % 2 > 0) winW = winW - 1; 
$("#popupCompare").css('top', (($(window).height()/2) - ($("#popupCompare").height()/2) + $(document).scrollTop())); 
$("#popupCompare").css('left', winW/2 - $("#popupCompare").width()/2); 

讓我知道你是否覺得它有用。

由於

+0

沒有工作,第一次它顯示隨機彈出和位置正確,我已更新我的完整彈出代碼 – abi1964

0

集中彈出窗口的最佳方法是使用CSS,而不是JavaScript。只有當你的情況變得非常動態時,JavaScript纔會派上用場,例如試圖迴應用戶的滾動,或者在你的網站上創建一些JavaScript廣告等等。但這是一個靜態的情況。請考慮彈出設計這些準則:

  1. 彈出只是一個簡單的模式對話框(覆蓋,如果你願意的話)與用戶進行交互的目的很簡單,像編輯一個簡單的記錄。所以,如果彈出窗口的尺寸變大,並且在那裏獲得越來越多的控件和交互,請考慮將設計更改爲將用戶重定向到另一個頁面,而不是彈出窗口。
  2. 有兩種類型的彈出窗口:1)模式,這意味着除非用戶處理彈出窗口,否則他不能訪問頁面的其餘部分。 2)非模態,這意味着用戶仍然可以訪問頁面的其餘部分,而與彈出窗口交互。
  3. 彈出窗口通常應該是可拖動的,因爲用戶可能需要拖動彈出窗口,所以他可以看到彈出窗口覆蓋的頁面部分。
  4. 一個彈出應該始終有一個關閉按鈕的地方(通常是非常在右上角顯式)

現在,我的建議是,請按照下列步驟操作:

  1. 創建一個div元素作爲body標記的最後一個元素。

    #screenCover { 位置:

  2. 這個CSS絕對定位它絕對的; top:0; right:0; bottom:0; left:0; 不透明度:0.5; //考慮爲Microsoft IE使用過濾器 z-index:9000; //阻止訪問後臺頁面,而半可見 }

  3. 那麼這screenCover格內創建另一個DIV

    popupContainer

    { 的位置是:絕對的; top:0; right:0; bottom:0; left:0; width:500px;/*這部分可以動態設置/ height:300px;/可以動態設置/ margin:auto;在後臺*/中心彈出/ }

  4. 現在把你彈出控制內部popupContainer