如何将此功能复制到另一个 div?
function goto(id, t){
//animate to the div id.
$(".headbox-wrapper").animate({"left": -($(id).position().left)}, 600);
// remove "active" class from all links inside #nav
$('#nav a').removeClass('active');
// add active class to the current link
$(t).addClass('active');
}
使用新名称和新 div,示例函数 2。
它和这个在同一页上,当我复制并打印新脚本时,它们都不起作用,这很明显。
最佳答案
基于 Beneto 的评论:
function goto(id, t){
$(".headbox-wrapper, .headbox-wrapper2").animate({"left": -($(id).position().left)}, 600);
$('#nav a').removeClass('active');
$(t).addClass('active');
}
HTML:
<div id='headbox-wrapper'>Click me!</div>
<div id='headbox-wrapper2'>Click me again!</div>
关于javascript - 使用新的 div 复制函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13551872/