JavaScript将背景图片设置为全屏

时间:2018-09-26 07:40:07

标签: javascript

您好,我正在尝试使用JavaScript将背景图片设置为全屏显示,但不是全屏显示而是重复?有人知道为什么会这样吗?

setInterval(function() {
  document.head.removeAttribute('style[data-trigger="zomb"]'); // remove all old styles as it has to add a new one on every update
  var value = document.getElementsByClassName('hud-intro-background')[0].value;

  var link = "<style type=\"text/css\" data-trigger=\"zomb\">.hud-intro::before {background: url('" + value + "'); background-size: 2560px 1320px;}</style>";
  document.head.innerHTML += link; // add the style tag to body
}, 1000);
var hudIntroLeft = document.getElementsByClassName('hud-intro-left')[0];
hudIntroLeft.classList.value = 'hud-intro-guide';
hudIntroLeft.childNodes[3].remove();
hudIntroLeft.style.marginRight = '20px';
hudIntroLeft.innerHTML = '<div class="hud-intro-guide-changelog"><h3>Background image</h3><small>Change intros background!</small><p>Paste down there the link of your image. (recommended size: 2560x1320)</strong><input type="text" class="hud-intro-background" placeholder="Background Image Link..."><button type="button" class="btn btn-green">Save background</button>'
document.getElementsByClassName('btn btn-green')[1].style.marginTop = '10px';
document.getElementsByClassName('hud-intro-background')[0].value = localStorage.oldbackground;
document.getElementsByClassName('btn btn-green')[1].onclick = function() {
  var value2 = document.getElementsByClassName('hud-intro-background')[0].value;
  let oldbackground = localStorage.setItem("oldbackground", value2);
};

0 个答案:

没有答案