11489 sujets

JavaScript, DOM et API Web HTML5

Pages :
(reprise du message précédent)

Si

remplace
$(document).ready(function() {
		$('.hrefToSmooth').click( function() { // Au clic sur un élément
			var rub = $(this).attr('href'); // rub cible
			var speed = 750; // Durée de l'animation (en ms)
			$('html, body').animate( { scrollTop: $(rub).offset().top }, speed ); // Go
			return false;
		});
});


par
$(document).ready(function() {
	$(function() {
	  $('.hrefToSmooth').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		  var target = $(this.hash);
		  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
		  if (target.length) {
			$('#contenu').animate({
			  scrollTop: $('#contenu').scrollTop() + target.offset().top - 20
			}, 1000);
			return false;
		  }
		}
	  });
	});
});
Pages :