0
我有2個寬度變化的容器。在他們裏面,我有可點擊的元素。點擊一個容器時,它將調整動畫大小。我想做到這一點,當點擊一個可點擊的元素時,它的容器調整大小並滾動到單擊的元素。下面是一個小提示:http://jsfiddle.net/w7H3M/1/JQuery ScrollTop在動畫中間嗎?
但是,由於調整大小,它滾動到錯誤的位置。以下是點擊事件處理程序:
<div id=left>...</div>
<div id=right>...</div>
$('#left').on('click', 'a', function() {
var node = $(this);
$('#left').animate({
width: 0.75 * $(document).width()
}, 800);
$('#right').animate({
width: 0.25 * $(document).width()
}, 800);
$('body').animate({
scrollTop: node.offset().top
}, 800);
});
$('#right').on('click', 'a', function() {
var node = $(this);
$('#left').animate({
width: 0.25 * $(document).width()
}, 800);
$('#right').animate({
width: 0.75 * $(document).width()
}, 800);
$('body').animate({
scrollTop: node.offset().top
}, 800);
});