2010-06-13 19 views
0

這是prettyphoto.js代碼段,我需要改變。 我想要實現的是每張照片都有一個隱藏的div或跨度,用於保存照片的描述。這樣我可以在描述中包含html。改變prettyphoto從div或跨度拉,而不是標題

可能嗎?

謝謝!

var images = new Array(), titles = new Array(), descriptions = new Array(); 
if(theGallery){ 
$('a[rel*='+theGallery+']').each(function(i){ 
    if($(this)[0] === $(_self)[0]) setPosition = i; // Get the position in the set 
    images.push($(this).attr('href')); 
    titles.push($(this).find('img').attr('alt')); 
    descriptions.push($(this).attr('title')); 
}); 
}else{ 
images = $(this).attr('href'); 
titles = ($(this).find('img').attr('alt')) ? $(this).find('img').attr('alt') : ''; 
descriptions = ($(this).attr('title')) ? $(this).attr('title') : ''; 
} 

$.prettyPhoto.open(images,titles,descriptions); 
return false; 

});

+0

我最初改變了上面的代碼來從longdesc或alt,而不是標題拉,但我仍然無法實現html中的描述。 – Jason 2010-06-13 16:34:55

+0

fancybox怎麼樣 - 可能嗎? http://www.copypastecode.com/30886/ – Jason 2010-06-13 20:00:54

+0

你用'.data()'來試試我的解決方案嗎?您可以存儲任何東西,並直接將其與元素相關聯。看起來像是一個很好的解決方案來滿足您的需 – user113716 2010-06-13 21:31:37

回答

0

只要跨度恰好在圖像後面,這應該可以工作(未測試)。

var images = new Array(), titles = new Array(), descriptions = new Array(); 
if(theGallery){ 
$('a[rel*='+theGallery+']').each(function(i){ 
    if($(this)[0] === $(_self)[0]) setPosition = i; // Get the position in the set 
    images.push($(this).attr('href')); 
    titles.push($(this).find('img').attr('alt')); 
    descriptions.push($(jQuery.sibling(this).next).text()); 
}); 
}else{ 
images = $(this).attr('href'); 
titles = ($(this).find('img').attr('alt')) ? $(this).find('img').attr('alt') : ''; 
descriptions = ($(jQuery.sibling(this).next).text()) ? $(jQuery.sibling(this).next).text() : ''; 
} 

$.prettyPhoto.open(images,titles,descriptions); 
return false; 
})); 
+0

我試過了,它打破了漂亮的照片功能。 – Jason 2010-06-13 18:54:22