jquery
  • fancybox
  • 2012-03-20 43 views 2 likes 
    2

    我正在使用FancyBox構建一個Web應用程序圖像庫。現在我正在追加 一個自定義div到彈出窗口(圖片),我需要放置圖片特定的鏈接。在Fancybox中替換附加div的內容

    如何在每次單擊旁邊的圖像時替換工具div的內容? 或者更好的是,是否有可能從彈出窗口內追加這個div?

    這是我的代碼:

    $(".iframe").fancybox ({ 
    
    afterShow: function() { 
    
    var toolbar = '<div id="tools">LINKS COME HERE</div>'; 
    
    $(".fancybox-inner").append(toolbar); 
    
    }, 
    
    maxWidth : 1200, 
    
    maxHeight : 550, 
    
    width  : '90%', 
    
    height  : '90%', 
    
    autoSize : false, 
    
    closeBtn : false, 
    
    openEffect : 'none', 
    
    closeEffect : 'none', 
    
    nextEffect: 'none', 
    
    prevEffect: 'none', 
    
    padding: 0, 
    
    scrolling: 'no' 
    
    }); 
    
    +0

    所以,它的工作原理?或者您還有其他問題嗎?我想我提供了一個有據可查的答案,所以有一點反饋將不勝感激;) – JFK 2012-03-23 20:25:03

    回答

    3

    我想你可以創建文檔的一個分離(隱藏)部分的內容(div的要追加)爲每個圖像像

    <div id="appendContent" style="display: none;"> 
    <div>content with links to be appended to the first image</div> 
    <div>content with links to be appended to the second image</div> 
    <div>content with links to be appended to the third image</div> 
    ... etc. 
    </div> 
    

    上面的結構假設您應該在您的畫廊中爲每個div有相同數量的圖像,例如:

    <a href="image01.jpg" class="fancybox" rel="gallery">image 01</a> 
    <a href="image02.jpg" class="fancybox" rel="gallery">image 02</a> 
    <a href="image03.jpg" class="fancybox" rel="gallery">image 03</a> 
    etc. 
    

    另外,你可以爲你的CSS樣式表中所附的div CSS選擇器,而不是使用.css()方法(如您的其他問題提出的建議),如:

    #tools { 
    position: absolute; 
    z-index: 99999; 
    bottom: 0px; 
    height: 20px; 
    border: 1px solid #ccc; 
    background: #fff; 
    width: 100%; 
    } 
    

    ...或者你需要的樣式設置。

    然後拉動每個div的內容,並在瀏覽圖庫時動態地將其附加到相應的圖像。

    使用afterShow回調選項,你可以這樣做:

    $(document).ready(function() { 
    $(".fancybox").fancybox({ 
        afterShow: function(){ 
        var toolbar = "<div id='tools'>" + $("#appendContent div").eq(this.index).html() + "</div>"; 
        $(".fancybox-inner").append(toolbar); 
        } 
    }); // fancybox 
    }); // ready 
    
    +0

    非常好的JFK。謝謝! – 2012-03-23 22:15:11

    +0

    如果我可以顯示/隱藏這個div,當我將鼠標懸停在圖像上時,會很酷,這樣我就可以訪問它中的鏈接。我怎樣才能做到這一點? – 2012-03-23 22:16:18

    +0

    檢查此http://stackoverflow.com/a/9125951/1055987 – JFK 2012-03-23 22:37:05

    相關問題