これは全体的な概念的な質問であるため、jQuery に関する質問ではありません。私の例では、上位の値が非線形に設定された div をコンテナーに取り込むことができます。それぞれの上部の値は、左にあるものの上部の位置とコンテナーの高さを考慮した式に基づいて計算されます (fiddle の 33 行目)。
//this formula sets the top value for each new child added to the container
//height is 100% of its parent which is 20% of the body
//newOne:last is the most recently added child and will have an initial top value of 10%
parseInt($(this).next().css('top'), 10) / $('#queue').height()) * 75 + (parseInt($('.newOne:last').css('top'), 10) * 2) + '%'
私は偶然にこれに出くわすことはあまりなく、「問題なく」動作しているように見えますが、最適化が明らかな場合は指摘してください:)ドラッグ イベント中に子をスムーズに処理します。左オフセットの操作に基づいて上部の値を調整する必要があると考えていますが、何時間もの実験の後、ドラッグを開始したときに元の位置をそのまま維持し、ドラッグ中に値をスムーズに調整し続けるものは見つかりませんでした引っ張る。左にドラッグすると、子は徐々に 10% の最小上限値に近づき (左オフセットが 0 の子は上限値が 10% になります)、右にドラッグすると、その上限値から徐々に元の位置に戻ります。 .
$('#queue').draggable({
axis: "x",
scroll: false,
drag: function(){
//adjust values of each child
$('.newOne').each(function(){
var percentLeft = $(this).offset().left / $('footer').width() * 100
var thisLeft = parseInt($(this).css('left'), 10) / $(window).width() * 100;
var thisTop = parseInt($(this).css('top'), 10) / $('#queue').height() * 100;
if (percentLeft >= 0){
//top value of each one gradually decreases...
//as it gets closer to an offset value of 0 and minimum top value of 10%
//non-linear attempt but not even close
//$(this).css('top', $(this).css('top', 10 + (thisTop - 10 / thisLeft) + '%'));
//linear step
$(this).css({'top': 8 + (percentLeft/2) + '%'});
}
});
}
});
PS私はここで多くのことを尋ねていることを知っていますが、うまくいけば誰かが挑戦します:)
更新: exp メソッドに出くわし、次のようなことをしました:
adjustTop = function(offset){
return 100 * (1.0-Math.min(0.98,(0.83 + ( 0.17/ (Math.exp(0.007*offset))) )) ) + '%';
};
$(this).css('top', adjustTop($(this).offset().left) );