L'original Plugin:
jQuery.fn.anchorAnimate = function(settings) {
settings = jQuery.extend({
speed : 1100
}, settings);
return this.each(function(){
var caller = this
$(caller).click(function (event) {
event.preventDefault()
var locationHref = window.location.href
var elementClick = $(caller).attr("href")
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
window.location.hash = elementClick
});
return false;
})
})
}
Modifié:
jQuery.fn.anchorAnimate = function(settings) {
settings = jQuery.extend({
speed : 1100,
offset: 0
}, settings);
return this.each(function(){
var caller = this
$(caller).click(function (event) {
event.preventDefault()
var locationHref = window.location.href
var elementClick = $(caller).attr("href")
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination+settings.offset}, settings.speed, function() {
window.location.hash = elementClick
});
return false;
})
})
}
Notez que je viens d'ajouter une option offset
. Donc, si votre div fixe a une hauteur de 60px puis il suffit d'appeler avec $('#whatever').anchorAnimate({offset: 60});
Merci !!!! J'ai essayé ceci en ajoutant une valeur statique, par ex. 60px. Mais je pense que "window.location.hash = elementClick" est le problème. – Vivid
Votre modification ne résout pas le problème. :-( – Vivid