我正在慢慢地弄清楚這一點。我有多個可調整大小的欄,其中有一個指針顯示其中的百分比。此時此更新所有小節指針,但只調整正在拖動的當前小節。我想要最初顯示數字,然後如果您選擇其中一個指針並將其拖動,唯一會更新其百分比的就是那一個。更新當前可調整大小的酒吧的百分比
這裏是我的HTML:
<div id="wrapper" class="clearfix">
<div class="r_bar"><span class="resizable" style="width: 34%;"><div class="marker"><p></p></div></span></div>
<br />
<div class="r_bar"><span class="resizable secondColor" style="width: 50%;" title="50"><div class="marker"><p></p></div></span></div>
</div>
這裏是我的jQuery至今:
$(function(){
var initialWidth = $(this).find('span').css('width').replace('%', '');
initialWidth = parseInt(initialWidth);
var dragging = false;
$('.resizable').mousedown(function(e){
dragging = true;
$(this).addClass('moving');
var parentOffset = $(this).parent().offset();
$this = $(e.currentTarget);
e.preventDefault();
$(document).mousemove(function(e){
if (dragging == true){
$this.css("width",e.pageX - parentOffset.left);
var percentageChange = (e.pageX - parentOffset.left)/initialWidth * 100
$('.moving p').html(percentageChange.toFixed(0));
}
});
});
$(document).mouseup(function(e){
if (dragging){
dragging = false;
$(this).removeClass("moving");
}
});
});
我不能讓酒吧的初始寬度基於內嵌式的寬度顯示並且無法隔離正在調整大小的當前欄並相應地更新百分比。如果有任何被拖動,所有小節數字更新。該欄不會在未被拖動的欄上移動...但該數字仍會更新。
有同樣的問題。 如果移動一個欄,數字更新就好了。但是,當你去和拖動另一個酒吧兩組數字同時更新相同的數字。
沒問題。謝謝......我喜歡你要去的地方。 – Amidude
我搞砸了一些,但它仍然在做同樣的事情。如果一個欄移動,數字更新就好了。但是,當你去和拖動另一個酒吧兩組數字同時更新相同的數字。 (仍然是Fiddlin) – Amidude