[英]Background image inside DIV is repeated
I have a js animated div image which is repeated underneath.我有一个在下面重复的 js 动画 div 图像。 I've checked and edited the css a few times but it has not worked, i think it could be in this part of the js code I have supplied.
我已经检查并编辑了 css 几次,但没有成功,我认为它可能在我提供的这部分 js 代码中。 Could someone please tell me how to apply no-repeat to the js?
有人可以告诉我如何对 js 应用 no-repeat 吗?
{
class Slide {
constructor(el) {
this.DOM = {el: el};
this.DOM.slideImg = this.DOM.el.querySelector('.slide__img');
this.bgImage = this.DOM.slideImg.style.backgroundImage;
this.layout();
}
layout() {
this.DOM.slideImg.innerHTML = `<div class='glitch__img' style='background-image: ${this.DOM.slideImg.style.backgroundImage};'></div>`.repeat(5);
this.DOM.glitchImgs = Array.from(this.DOM.slideImg.querySelectorAll('.glitch__img'));
}
changeBGImage(bgimage, pos = 0, delay = 0) {
setTimeout(() => this.DOM.glitchImgs[pos].style.backgroundImage = bgimage, delay);
}
}
The JavaScript syntax to apply CSS background-repeat Property to an element is:将 CSS 背景重复属性应用于元素的 JavaScript 语法是:
object.style.backgroundRepeat= "no-repeat";
in this case, object
is the element to apply the property and value on.在这种情况下,
object
是应用属性和值的元素。
If your ._slide_img
needs a no-repeat
, you can just put that in the CSS?如果你的
._slide_img
需要一个no-repeat
,你可以把它放在 CSS 中?
CSS file CSS 文件
.slide_img {
background-repeat:no-repeat;
}
If that doesn't work there's probably something else in your code that prevents it.如果这不起作用,那么您的代码中可能还有其他东西阻止了它。 In that case please include all your code so we can reproduce your problem.
在这种情况下,请包含您的所有代码,以便我们重现您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.