gpt4 book ai didi

javascript - jQuery UI slider 动画不更新 ui 值

转载 作者:行者123 更新时间:2023-11-28 07:32:42 24 4
gpt4 key购买 nike

如何在页面加载时使用自动更新值来制作 jQuery ui slider 动画。

当页面加载时,应该从左到右进行动画处理,问题是当 slider 开始进行动画处理时,值不会更新

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">

</head>
<body>

<p>
<label for="amount">Minimum number of bedrooms:</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range-max"></div>
<!-- Scripts -->
<script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<script>
$(function() {
$( "#slider-range-max" ).slider({
range: "max",
min: 0,
max: 10000,
step: 100,
value: 0,
animate: true,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value );
},
change: function( event, ui ) {
$( "#amount" ).val( ui.value );
}
});
$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );
$('.ui-slider-handle').animate({
left: '0%'
}, 1500, 'linear').animate({
left: '50%'
}, 1200, 'linear').animate({
left: '40%'
}, 1300, 'linear');
});

</script>
</body>
</html>

最佳答案

为了将初始动画期间的值变化同步到输入量,您可以使用动画的步骤事件和现在值。如果您希望当用户更改值时每个动画步骤的金额发生变化,您将需要在幻灯片事件中执行类似的操作。

$(function() {
var maxValue = 10000;

$( "#slider-range-max" ).slider({
range: "max",
min: 0,
max: maxValue,
step: 100,
value: 0,
animate: true,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value );
},
change: function( event, ui ) {
$( "#amount" ).val( ui.value );
}
});

$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );

$('.ui-slider-handle')
.animate({ left: '0%' },
{
duration: 1500,
easing: 'linear',
step: function (now) {
if (now <= 0)
return;

$("#amount").val(Math.round((now / 100) * maxValue));
}
})
.animate({ left: '50%' },
{
duration: 1200,
easing: 'linear',
step: function (now) {
if (now <= 0)
return;

$("#amount").val(Math.round((now / 100) * maxValue));
}
})
.animate({ left: '40%' },
{
duration: 1300,
easing: 'linear',
step: function (now) {
if (now <= 0)
return;

$("#amount").val(Math.round((now / 100) * maxValue));
}
});
});
});

关于javascript - jQuery UI slider 动画不更新 ui 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28943008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com