以下是我的想法:
点击
滚动到<div>
很难解释(我是法国人)所以试试吧: http://mathieualbore.com/traci/
当你从smilio点击时它起作用&gt;如果从skiply开始并单击&gt;则跳过但不起作用; smilio
代码:
$("#smilio").waypoint({
handler: function(event, direction) {
left = $('.menu li[data-target="#smilio"]').position().left;
w = $('.menu li[data-target="#smilio"] span').width();
$('.active').stop().animate({ left: left, width: w+40 })
},
offset: 40
});
$("#skiply").waypoint({
handler:
function(event, direction) {
left = $('.menu li[data-target="#skiply"]').position().left;
w = $('.menu li[data-target="#skiply"] span').width();
$('.active').stop().animate({ left: left, width: w+40 })
},
offset: 40
});
和
$(".menu li").click(function() {
var target = $(this).data("target");
var scrollY = $(target).position().top;
$("html, body").animate({ scrollTop: scrollY-40 }, 500);
}
答案 0 :(得分:0)
如果有人有兴趣,我会找到办法解决问题
$(".menu li, a").click(function() {
var target = $(this).data("target");
var scrollY = $(target).position().top;
$("html, body").animate({
scrollTop: scrollY-40
}, 500, function() {
left = $('.menu li[data-target="'+target+'"]').position().left;
w = $('.menu li[data-target="'+target+'"]').width();
$('.active').stop().animate({
left: left,
width: w+40
})
});
});
答案 1 :(得分:0)
这是为了简化航点:
$(".menu li").each(function() {
var target = $(this).data("target");
$(target).waypoint({
handler: function(event, direction) {
left = $('.menu li[data-target="'+target+'"]').position().left;
w = $('.menu li[data-target="'+target+'"]').width();
$('.active').stop().animate({ left: left, width: w+40 })
},
offset: 40
});
});