As images to set the size?



<style>
#fixedbutton {
 position: fixed;
 bottom: 5px;
 right: 5px; 
}
</style>


<script type="text/javascript">
(function() {
 var i = 0;
 var src = [
'images/1.jpg',
'images/2.jpg',
'images/3.jpg',
'images/4.jpg',
'images/5.jpg',
'images/6.jpg',
'images/7.jpg'
];
 var l = src.length;
 var t;

 for(i = 0; i < l; i++) {
 var img = new Image();
 img.src = src[i];
 img.onload = function() {
 delete this;
}
}

 i = 0;
 t = setInterval(function() {
 if(i === l){
clearInterval(t);
 } else {
 document.body.style.background = 'url(' + src[i] + ') center top no-repeat';
}
i++;
 }, 1000);
})();
</script>
 <a href="../index.html"><img src="images/upbutton.jpg" id="fixedbutton"></a>

June 7th 19 at 14:33
2 answers
June 7th 19 at 14:35
There are several options.
You can hang the picture using img windth.setAttribute or css to register the class under the picture and assign your images with this class through the img.classList.add
could you give us an example? - Randall63 commented on June 7th 19 at 14:38
June 7th 19 at 14:37
Image sizes can be set when creating an instance of Image

var img = new Image();

//or so: the constructor of the Image class taking two arguments, width and height
var width = 400; //width
var height = 100; //height
var img = new Image(width, height);

//or, the third option, when the element directly change the properties
var img = new Image();
img.width = width; //this is the variable that must be defined
img.height = height; //this too
put the second option in the code and nothing happens - Randall63 commented on June 7th 19 at 14:40

Find more questions by tags JavaScriptHTMLCSS