K
K
Kircha2018-03-03 15:22:47
css
Kircha, 2018-03-03 15:22:47

How to size images?

<!DOCTYPE html>
<html><head>
<style>
#fixedbutton {
    position: fixed;
    bottom: 5px;
    right: 5px; 
}
</style>
</head>
<body>
<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>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Counter, 2018-03-03
@Counter

There are several options.
You can add windth to the image via img.setAttribute or add a class for images in css and assign this class to your images via img.classList.add

F
fomenko_alexandr, 2018-03-04
@fomenko_alexandr

Image dimensions can be set when creating an Image instance

var img = new Image();

//или так: конструктор класса Image принимает два аргумента - ширину и высоту
var width = 400; //ширина
var height = 100; //высота
var img = new Image(width, height);

//или третий вариант, когда элементу напрямую меняют свойства
var img = new Image();
img.width = width; //это переменная, которая должна быть определена
img.height = height;  //это тоже

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question