简体   繁体   English

使用范围滑块更改div高度

[英]Using range slider to change div height

Seen examples using the range input to control rotation of a div with javascript, but cant see how to change it to other properties such as height and opacity. 看到了一些示例,这些示例使用range输入来使用javascript控制div的旋转,但是看不到如何将其更改为其他属性,例如高度和不透明度。 Here is an example: 这是一个例子:

function rotate(value)
{
x=document.getElementById('div1')
x.style.webkitTransform="rotate(" + value + "deg)"; 
}


<input type="range" min="0" max="360" value="0" onchange="rotate(this.value)">

Thanks for any help. 谢谢你的帮助。

<script type="text/javascript">
function divHeight(value)
{
    var x = document.getElementById('div1');
    x.style.height=value+"px"; 
}
</script>


<input type="range" min="0" value="0" onchange="divHeight(this.value)">

For a more generalized solution, you can create a generic setStyleOn method. 对于更通用的解决方案,可以创建一个通用的setStyleOn方法。 jsFiddle jsFiddle

JS: JS:

function setStyleOn(rule, targetId, value) {
    x = document.getElementById(targetId);
    x.style[rule] = value;
}

HTML: HTML:

<label>Rotation</label>
<input type="range" min="0" max="360" value="0" 
    onchange="setStyleOn('webkitTransform', 'div1', 'rotate(' + this.value + 'deg')">
<label>Opacity</label>
<input type='range' min='0' max='1.0' value='1.0' step='0.1' 
    onchange="setStyleOn('opacity', 'div1', this.value)" />
<label>Height</label>
<input type='range' min='0' max='100' value='10' step='1' 
    onchange="setStyleOn('height', 'div1', this.value + 'em')" />    
<label>Width</label>
<input type='range' min='0' max='100' value='10' step='1' 
    onchange="setStyleOn('width', 'div1', this.value + 'em')" />    
<div id="div1">
</div>

There are many functions explained for example on this site . 例如, 此站点上说明了许多功能。

For changing height: you can use scale(), for moving position: translate(), for skewing shape: skew() etc... 要更改高度:您可以使用scale(),移动位置:translate(),倾斜形状:skew()等。

For opacity, use opacity property . 对于不透明度,请使用opacity属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM