我有这样的代码:
$(".jumper").on("click", function( e ) {
e.preventDefault();
$("body, html").animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, 600);
});
这就是它的工作方式http://jsfiddle.net/ZVdRt/291/
如何制作一个菜单,当 pilip 或 Ploop 丰富特定级别时改变背景?
对不起我的语言;)这是帖子 http://www.theverge.com/2014/4/14/5608222/samsung-galaxy-s5-review 中 TheVerge float 菜单的示例
最佳答案
如果我没理解错的话,您想要的是在链接到达目的地(滚动结束)后更改链接的背景。这可以通过使用animate 的complete 函数来完成:
$(".jumper").on("click", function( e ) {
e.preventDefault();
// reset background for all jumpers, and save current one
$(".jumper").css("background","");
obj = this;
$("body, html").animate(
{
scrollTop: $( $(this).attr('href') ).offset().top
},
600,
function() {
// change background for current jumper when the animation is completed
$(obj).css("background","black");
});
});
我希望这就是你的意思。你可以看到它在这个链接上工作:http://jsfiddle.net/ZVdRt/298/ (我还在您的#menu CSS 中添加了一个 z-index,这样关键字就不会与它重叠。)
关于jquery - 像 TheVerge 上的 float 菜单评论帖子 Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24013820/