[英]Changing div width using JQuery UI slider
I am trying to dynamically change the width of a div using a slider. 我正在尝试使用滑块动态更改div的宽度。 I get the element ID by using a click function.
我通过单击功能获得了元素ID。 I then pass this ID into a variable.
然后,我将此ID传递给变量。 I use this variable to determine which element ID i am adjusting Everything works fine except for the last line.
我使用此变量来确定我要调整的元素ID,除最后一行外,其他所有东西都正常运行。 Nothing happens and no errors.
什么也没有发生,没有错误。
Just to clarify a little more, in the JS fiddle when you drag it will update the selected element. 只是为了澄清一点,在JS小提琴中,当您拖动它时,它将更新选定的元素。 How do i bring that element into the slider to adjust its width?
如何将元素带入滑块以调整其宽度? I have tried getting the id attribute of the element and storing it in a global variable and then calling that variable in the slider and updating its CSS.
我尝试获取元素的id属性并将其存储在全局变量中,然后在滑块中调用该变量并更新其CSS。 JSFiddle
JSFiddle
UPDATE: Solved! 更新:解决了! I should have added a class onto the selected element instead of trying to store it in a variable.
我应该在所选元素上添加一个类,而不是尝试将其存储在变量中。 var divHolder // holds element from click function
var divHolder //保存click函数中的元素
$('#changeWidth').slider({
value: 0,
slide: function(event, slider) {
var theSliderValue = slider.value + "%";
alert(divHolder); // Returns the div id i wanted
$("#divHolder").css("width", theSliderValue);
}
});
Is this basically what you're trying to do? 这基本上就是您要尝试做的吗?
https://jsfiddle.net/02o6a583/3/ https://jsfiddle.net/02o6a583/3/
$('.slider').slider({
values: [0, 100],
slide: function(event, ui){
$('.expand-me').css('width', ui.value + '%');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.