2012-03-19 105 views
0

我試圖從每個縮略圖加載圖像並添加一個Opentip(opentip.org)。原型 - 函數內每個() - 只返回最後一個值

我已成功添加標籤並創建工具提示。唯一的問題是隻顯示數組中的最後一個值 - 對於每個縮略圖。

下面是一個產品的鏈接:http://www.inusual.com.br/poltrona-evo.html

原始的HTML是

<div class="ca-thumbnails"> 
    <div> 
     <img src="xxx"> 
    </div> 
    <div> 
     <img src="xxx"> 
    </div> 
</div> 

我已經添加了隨機。一切工作正常,並正確添加到每個img。只有圖像沒有顯示好。

var tip = $$('.ca-thumbnails div img'); 
tip.each(function(s, index) { 

    src = s.readAttribute('src'); 
    function image() { 

    return Builder.node('img', { 'src': src }); 
    } 

    s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src}); 
    s.up(0).addTip(image, { ajax: false, showEffect: 'appear', showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true, tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] }); 

我相信函數image()只獲取最後一項。

有沒有人有這方面的線索? 對不起,我的英語。

感謝

+0

什麼是Builder? – clockworkgeek 2012-03-20 17:32:25

回答

1

,當你期待image功能是沒有得到調用。我不是100%確定它爲什麼沒有錯誤,但是不是將一個元素傳遞給addTip,而是傳入一個函數引用(image)。試試這個,看看它是否修復該問題:

var tip = $$('.ca-thumbnails div img'); 
tip.each(function(s, index) { 

    var src = s.readAttribute('src'); 
    var image = new Element('img', {src: src}); 

    s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src}); 
    s.up(0).addTip(image, { ajax: false, showEffect: 'appear', showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true, tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] }); 
}); 

不要忘記使用var關鍵字!我看到你有一個全局變量image,它可能(或可能不)與這些特定代碼行沒有出錯併爲你提供線索有什麼不對之處有關。