Using input type=“range” to scale an image

我的未来我决定 提交于 2019-12-13 05:43:02

问题


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:


<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.



来源:https://stackoverflow.com/questions/15634036/using-input-type-range-to-scale-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!