Jquery .css('background', 'value');不工作


由于某些原因,jQuery.css("background",无法工作。有人知道如何让它发挥作用吗?我正在尝试以下代码。
jQuery('.image').css('background', 'url("/image.jpg") no-repeat cover bottom');

这就是你可以在下面看到的工作。

$(document).ready(function()
{
jQuery('.image').css('background', 'url(https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQTpEb2TLuGVF1Y72YDsvLC60_xgaZoMUrieRpkHoxUWMHf30o3) bottom / cover no-repeat');
});
.image
{
height:500px;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	<title></title>
</head>
<body>
<div class="image"></div>
</body>
</html>

有效的background-position应在background-size之前,并在两者之间放置一个/

https://www.w3.org/TR/css-backgrounds-3/#the-背景

<bg-layer> = <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box> || <box>

CSS

background: url(/image.jpg) bottom / cover no-repeat;

Jquery

jQuery('.image').css('background', 'url(/image.jpg) bottom / cover no-repeat');

最新更新