最初の li にマージン オフセットを与えることで、クリックした li を中央に (または十分近くに) 押し込みたいと考えています。私の問題は、算術を行う方法が完全にわからないことです。
私が試したのは、li の総数を 2 で割り、li の幅を掛けることです。これが中心点になると思いました。それに応じて機能しませんでした。
私は困惑しています。
// set .active class when an li is clicked and push that li to the centre (or close enough.)
$('body').on("click", ".date li", function () {
var self = $(this),
li = $('.date li');
li.removeClass('active');
self.addClass('active');
var num = self.index(),
w = self.width(),
t = w * (num / 2);
t = t + 'px';
// push the margin of the first li
$('.date li:first-child').animate({ 'margin-left': t });
});
問題のフィドルは次のとおりです。http://jsfiddle.net/vLQgy/1/