1
我有一個小問題,我想從數據屬性中獲取「路徑」並添加到背景。jQuery從數據屬性獲取路徑
HTML
<div>
<div data-image="../images/header.jpg"></div>
</div>
jQuery的
$('[data-image]').css(
{
background: "url("+$(this).data('image')+") no-repeat center",
backgroundSize: "cover",
height: ($(document).height()/ 3)
}
);
你有任何想法如何做到這一點?
是否有與數據屬性超過一個元素?如果是這樣,請使用'each' – adeneo 2014-12-27 14:05:30