2012-04-05 96 views
0

編輯:問題可以在這裏看到:http://school.collegebrain.com/images/university-of-washington/。它只發生了1/15次,但這仍然是太頻繁。fancybox圖像有時會渲染外框

我有以下的Django模板:

<script type="text/javascript" src="{{ STATIC_URL }}js/ 
jquery.fancybox-1.3.4.pack.js"></script> 
<link rel="stylesheet" href="{{ STATIC_URL }}css/ 
jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> 
{% include "submission-form.html" with section="photos" %} 
<div class="commentables"> 
     {% load thumbnail %} 
    {% for story in objects %} 
      <div class="image {% if forloop.counter|add:"-1"| 
divisibleby:picsinrow %}left{% else %}{% if forloop.counter| 
divisibleby:picsinrow %}right{% else %}middle{% endif %}{% endif %}"> 
       {% if story.image %} 
        {% thumbnail story.image size crop="center" as full_im %} 
           <a rel="gallery" href="{% url post slug=story.slug %}"> 
           <img class="preview" {% if story.title %} 
alt="{{ story.title }}" {% endif %} src="{{ full_im.url }}" full- 
image="{% if story.image_url %}{{ story.image_url }}{% else %} 
{{ story.image.url }}{% endif %}"> 
             </a> 
        {% endthumbnail %} 
       {% else %} 
         {% if story.image_url %} 
          {% thumbnail story.image_url size crop="center" as 
full_im %} 
           <a rel="gallery" href="{% url post slug=story.slug %}"> 
             <img class="preview" {% if story.title %} 
alt="{{ story.title }}" {% endif %} src="{{ full_im.url }}" full- 
image="{{ story.image_url }}"> 
               </a> 
          {% endthumbnail %} 
         {% endif %} 
       {% endif %} 
     </div> 
    {% endfor %} 
     {% if rowid != "last" %} 
     <br style="clear: both" /> 
     {% endif %} 
    {% if not no_more_button %} 
    <p style="text-align: right;" class="more-results"><a href="{% url 
images school_slug tag_slug %}">more...</a></p> 
    {% endif %} 
</div> 
<script> 
    $(document).ready(function(){ 
     function changeattr(e){ 
      var f = $(e.clone()); 
      $(f.children()[0]).attr('src', $(f.children() 
[0]).attr("full-image")); 
      $(f.children()[0]).attr('height', '500px'); 
      return f[0].outerHTML; 
     } 
     $('.image a').each(function(idx, elem) { 
      var e = $(elem); 
      e.fancybox({ 
       title: $(e.children()[0]).attr('alt'), 
      content: changeattr(e) 
      }); 
     }); 
    }); 
</script> 

,我偶爾會越來越怪異的顯示錯誤在該框將 要麼不呈現在所有東西(所以它會顯示爲只是薄薄的白色 基本上),或者它只會渲染大約30像素寬,並且 會在頁面中間位置一半。在這兩種情況下,如果我檢查 元素,我可以看到完整圖片的「陰影」,在正確的 大小,與正確的URL。

圖像源似乎沒有什麼差異,我沒有得到 錯誤,並且這在Chrome和Firefox中都有發生。 有沒有人有任何想法?

編輯:上搞砸了一箱視圖選擇源給

<div id="fancybox-outer"><div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div><div style="border-width: 10px; width: 165px; height: auto; opacity: 1;" id="fancybox-content"><div style="width: auto; height: auto; overflow: auto; position: relative;"><a rel="gallery" href="/post/shit-is-about-to-get-real/"> 
          <img class="preview" alt="shit IS about to get real" src="http://i.imgur.com/Le8Kv.jpg" full-image="http://i.imgur.com/Le8Kv.jpg" height="500px"> 
         </a></div></div><a style="display: inline;" id="fancybox-close"></a><a style="display: inline;" href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a><a style="display: inline;" href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a></div> 
+0

而不是所有這些代碼。在您的網頁上查看源代碼併發布。 – 2012-04-05 23:34:35

+0

這個問題和這個問題之間的關係是什麼http://stackoverflow.com/q/10035575/1055987? – JFK 2012-04-08 05:02:51

+1

您發佈的內容是「我如何在彈出框中顯示正確的內容?」這一個是「現在我彈出了正確的東西,我如何使彈出始終正確加載?」 – Colleen 2012-04-09 16:13:35

回答

0

我與任何有關圖片和javascript問題的第一個建議就是務必JavaScript知道圖像的大小。設置尺寸(寬度和高度),看看你的問題是否得到解決。

+0

我對設置特定尺寸的擔憂是我不希望較小的圖像被拉伸。 – Colleen 2012-04-09 19:04:11

+0

對不起,並不意味着你應該拉伸它,我只是想知道是否將圖像尺寸設置爲它們應該(加載時)會修復問題。如果這可以修復渲染問題,那麼我們可以討論可能需要採取哪些CSS調整來修復佈局。 – mikevoermans 2012-04-09 19:51:30

+0

好的。我應該在哪裏設置圖像大小? (例如,通過js,作爲圖像標籤本身的屬性,作爲css屬性..?) – Colleen 2012-04-09 21:27:56