gpt4 book ai didi

jquery - Ui slider 一次侧 slider

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:13 24 4
gpt4 key购买 nike

Jquery ui slider can one side enter image description here

如果 Larger 箭头移动到一侧无法拖动到反向位置,如何在拖动箭头后解决此问题。

例如,一旦它达到 2 就不能来 1,它想移动 3,然后再移动 3。

这是我的代码:

<html>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function update() {
var tasks_time = $('#tasks_time').slider('value');
var tasks_done = $('#tasks_done').slider('value');
var total_cost = (tasks_time * 4 * tasks_done) / (tasks_done * 3);
var credits_needed = Math.round((total_cost / 10) + 1);
$("#total_cost").text(total_cost.toFixed(2));
$("#curr-tasks_time").text(tasks_time);
$("#curr-tasks_done").text(tasks_done);
$("#credits_needed").text(credits_needed.toFixed(0));
}
$("#tasks_time").slider({
value: 1,
min: 0,
max: 72,
step: 1,
slide: function() {
update();
}
});
});
</script>
<style>
.ui-widget-content { border: 1px solid #ccc; background: #ff9900 url(images/ui-bg_flat_100_ff9900_40x100.png) 50% 50% repeat-x; color: #222222; }
.ui-widget-header { border: 1px solid #aaaaaa; background: #797979 url(images/ui-bg_highlight-soft_75_797979_1x100.png) 50% 50% repeat-x; color: #222222; font-weight: bold; }
.ui-slider { position: relative; text-align: left; }
.ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 1.2em; height: 1.2em; cursor: default; }
.ui-slider .ui-slider-range { position: absolute; z-index: 1; font-size: .7em; display: block; border: 0; background-position: 0 0; }
.ui-slider-horizontal { height: .8em; }
.ui-slider-horizontal .ui-slider-handle { top: -.3em; margin-left: -.6em; }
.ui-slider-horizontal .ui-slider-range { top: 0; height: 100%; }
.ui-slider-horizontal .ui-slider-range-min { left: 0; }
.ui-slider-horizontal .ui-slider-range-max { right: 0;}
</style>
</head>
<body>
Finish these items in <span id="curr-tasks_time" class="calc_number">1</span> hours
<div id="tasks_time">
</div>
</body>
</html>

JSFiddle

最佳答案

我更新了你的 fiddle ,逻辑如下:

  1. 注册拖动 slider 时的起始值
  2. 滑动时,检查当前值是否大于起始值
  3. 如果当前值小于起始值,则锁定 slider 。

查看演示: http://jsfiddle.net/EAaLK/906/

$(document).ready(function(){

function update() {
var tasks_time = $('#tasks_time').slider('value');
var tasks_done = $('#tasks_done').slider('value');
var total_cost = (tasks_time * 4 * tasks_done) / (tasks_done * 3);
var credits_needed = Math.round((total_cost / 10)+1);
var startVal; //Register the value when dragging is starting.
$("#total_cost").text(total_cost.toFixed(2));
$("#curr-tasks_time").text(tasks_time);
$("#curr-tasks_done").text(tasks_done);
$("#credits_needed").text(credits_needed.toFixed(0));

}

$("#tasks_time").slider({
value: 1,
min: 0,
max: 72,
step: 1,
start: function(e, ui){
startVal = ui.value;
},
slide: function(e, ui) {
if(ui.value < startVal){
//Temporarily disable to slider
$(this).slider('disable');
}else{
update();
}
},
stop: function(){
//Check if slider has been disabled
if($(this).slider( "option", "disabled" )){
//If Yes then reset value to starting value
//and then re-enable slider
$(this).slider('value', startVal);
$(this).slider('enable');
}
}
});


});

关于jquery - Ui slider 一次侧 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21180223/

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