2013-03-18 33 views
0

我在新項目的多個位置使用jQuery Innerfade,我希望能夠將容器高度值動態地傳遞給附加到容器的數據屬性,而不是改變jQuery的每個實例,比如我想通過容器高度在HTML如下:在數據屬性中傳遞jQuery InnerFade高度值

HTML:

<div class="fade" data-height="190"> 
     <a href="#" title=""><img src="http://placehold.it/190x190&text=Brand%201" alt=""></a> 
     <a href="#" title=""><img src="http://placehold.it/190x190&text=Brand%202" alt=""></a> 
     <a href="#" title=""><img src="http://placehold.it/190x190&text=Brand%203" alt=""></a> 
</div> 

然後從任何實例獲得附加的高度如下:

$('.fade').innerFade({ 
    containerHeight: $(this).attr('data-height')+'px' 
}); 

我上面有什麼不起作用,但它應該給你我想要達到的要點。基本上我想獲取有關元素的數據高度屬性。

回答

0

你嘗試過這...

containerHeight: '"' + $('.fade').attr('data-height') + 'px"' 
+0

謝謝,但似乎並沒有工作......我想我的示例代碼其實是錯誤的,我已經改成了展示我試圖實現!抱歉! – 2013-03-18 16:46:01

+0

發佈您的原始代碼並清楚地說明您嘗試訪問的位置,這種方式可以幫助您解決問題。 – blackhawk 2013-03-18 16:51:19

+0

完成但會添加一些額外的細節。 :) – 2013-03-18 21:14:16