[英]jquery UI: adjust width of div by slider change
I use jquery UI slider and want onchange to adjust a width of a div: 我使用jquery UI滑块并希望onchange调整div的宽度:
$('#slider').slider({
value: [17],
change: handleSliderChange
});
function handleSliderChange(){
...
}
here the html 这里的HTML
<div id="slider"></div>
<div id="vardiv" style="width:300px;height:20px;border:3px solid black"> Testing </div>
i want that by adjusting the slider the width of the div #vardiv should be adjusted proportionally. 我希望通过调整滑块,div #vardiv的宽度应按比例调整。
I guess we have to calculate a bit and use some functions. 我想我们必须计算一下并使用一些函数。
THX 4 your support. THX 4你的支持。
the change function would only be called after releasing the mouse, if you want to have realtime effect you can use the slide function like this: 只有在释放鼠标后才会调用更改功能,如果你想要实时效果,你可以使用这样的滑动功能:
$('#slider').slider({
value: 17,
slide: handleSliderChange
});
function handleSliderChange(event, slider){
$('#vardiv').css('width', slider.value + '%');
$("#vardiv").text(slider.value + '%');
}
working example: http://jsfiddle.net/saelfaer/WXfkK/1/ 工作实例: http : //jsfiddle.net/saelfaer/WXfkK/1/
To get this behavior I would write something like this, to get it short. 为了得到这种行为,我会写这样的东西,简而言之。
$("#slider").slider({
change: function (event, ui) {
$("#vardiv").css("width", ui.value + "%");
}
});
This event will executes everytime the slider changes. 每次滑块更改时都会执行此事件。 Inside that event the vardiv element will get a new proportionally width to it´s parent.
在该事件中,vardiv元素将获得与其父级成比例的新宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.