Using input type=“range” to scale an image

2019-09-11 07:42发布

What the title says. Is it possible? I want an image to scale up and down from it's center using a slider such as the input type="range".

Thanks in advance!

1条回答
欢心
2楼-- · 2019-09-11 08:17
<input id="ranger" type="range" min="1" max="100" value="100" />
<hr />
<img id="image" src="http://google.com/images/logo.png" width="275" height="95" />

var ranger = document.getElementById('ranger'),
    image =  document.getElementById('image'),
    width = image.width,
    height = image.height;

ranger.onchange = function(){
    image.width = width * (ranger.value / 100);
    image.height = height * (ranger.value / 100);
}

Demo: http://jsfiddle.net/DnE83/1/

Study it, work out how it works.

查看更多
登录 后发表回答