2012-01-15 108 views
1

我有一個網頁,其中有幾個打開Colorboxes的鏈接。除了一個以外,所有鏈接都能正常工作。問題鏈接在大多數方面都可以正常工作,但是當打開colorbox時,它會比參數中指定的大,然後縮小到正確的大小。Colorbox以錯誤的尺寸打開,然後縮小到正確的尺寸

我在網上發現了一個類似的問題(無法回想,如果它是在Stackoverflow),通過確保在腳本之前加載的colorbox css文件解決了這個問題。我做到了,但沒有任何區別。

在頁面上的各種顏色框中,這是唯一包含表單或做任何ajax的東西。這可能不是相關的,但它是我可以看到這個彩盒和其他工作正常的唯一真正的區別。

該鏈接的代碼是:<a href="notifyList.cgi?bibId={$bibId}" rel="notifyMe" id="notifyFormLink">Notify Me</a>

jQuery的代碼如下粘貼。任何幫助將不勝感激。

    $(function(){ 
         $('#notifyFormLink').colorbox({ 
           width:300, 
           height:270, 
           opacity:0, 
           transition:"none", 
           scrolling:false, 
           onComplete: function() { 
            notifySubmit(); 
           }}); // end colorbox 
        }); // end anon function       

        function notifySubmit() { 
         // $.colorbox.resize(); 
         $('#emailNotify').focus(); 
         $("#notifyForm").submit(function(){ 
          var input = $('#emailNotify').val(); 
          if (input.match(/^[\w\d\.\+][email protected][\w\d\.\+]+$/)) { 
           $.get(
            $(this).attr('action'), 
            $(this).serialize(), 
            function(data){ 
             $().colorbox({ 
              html: data, 
              width:300, 
              height:270, 
              opacity:0, 
              transition:"none", 
              scrolling:false, 
              onComplete: function() { 
               notifySubmit(); 
               }}); 
              } // end data 
             ); // end get 
             return false; 
          } else { 
           $('#validationResponse').html('<span style="font-size:12px">Bad e-mail: please try again.</span>'); 
           return false;  
          } 
         }); // end submit 
        } // end notifySubmit 
+0

有趣的問題,和偉大的示例代碼,順便說一句。假設你已經嘗試了initialHeight和initialWidth參數?另外,如果你使用ID綁定,爲什麼還要使用REL屬性? – 2012-01-15 18:08:18

+0

非常感謝,凱文!我沒有嘗試initialHeight和initialWidth參數。我發現,如果將這些與innerHeight和innerWidth(而不是常規的高度和寬度參數)結合使用,則顏色框會以正確的大小顯示並保持原樣。再次,非常感謝幫助我克服這個令人沮喪的問題。 – anaximander 2012-01-15 19:13:43

回答

0

顯然,答案是在此用例中使用initialHeght和initialWidth屬性與innerHeight和innerWidth結合使用。