I call jquery function onclick at links. For example:
Content 1
If you have the tags in a parent element with an id, you can do this:
$('#parent_element_of_links a').click(function(e) {
e.preventDefault();
$('#parent_element_of_links a').removeClass('active');
$(this).addClass('active');
});
Working example: http://jsfiddle.net/fDZ97/
You could also just put the code above in your Animate2id() function that you have:
function Animate2id(id, ease) {
var animSpeed = 2000;
var $container = $("#container");
if (ease) {
var easeType = ease;
} else {
var easeType = "easeOutQuart";
}
$container.stop().animate({
"left": -($(id).position().left)
}, animSpeed, easeType);
// remove "active" class from all links, add it to this one
$('#parent_element_of_links a').removeClass('active');
$(this).addClass('active');
}
The this keyword wasn't working because it was referring to the window rather than the link. So I added an extra parameter in the function and it works perfectly now, just remember to add this in the onclick (right before you define the ease variable):
function Animate2id(id, t, ease) {
var animSpeed = 2000;
var $container = $("#container");
if (ease) {
var easeType = ease;
} else {
var easeType = "easeOutQuart";
}
$container.stop().animate({
"left": $(id).position().left
}, animSpeed, easeType);
// remove "active" class from all links, add it to this one
$('#links a').removeClass('active');
$(t).addClass('active');
}
Working jsFiddle Example: http://jsfiddle.net/Uqqmy/