0
我正在使用jQuery animate(
函數,它包含以下內容。如何在jQuery中的.animate()之後更改背景圖像的不透明度?
$(document).ready(function(){
setInterval(function(){
$("#animate1").fadeIn('slow').animate({
'margin-left': '150px',
'margin-bottom': '50px'
}, 2000).fadeOut();
$("#animate1").fadeIn('slow').animate({
'margin-bottom': '0px',
'margin-left': '-140px'
}, 2000).fadeOut();
}, 300);
});
<div style="background-image:url('img/sofa.jpg');">
<div id="animate1">
<img src="img/chotu.png" style="height:200px; width:200px;"/>
</div>
</div>
我想改變我的background-image
不透明度爲:
$("#animate1").fadeIn('slow').animate({
'margin-left': '150px',
'margin-bottom': '50px'
}, 2000)./* change bg-opacity here */.fadeOut();
這可能嗎?我只是想在我的第一個動畫函數後改變我的背景圖像不透明度。
你不能直接影響到背景的不透明度。你只能改變整個元素的「不透明度」。另外,在同一個實例中,不會改變元素背景的不透明度,因爲它會使該元素完全失去冗餘? –
您可以使用僞元素,請參閱https://scotch.io/tutorials/how-to-change-a-css-background-images-opacity –