2014-05-21 2 views
0

Les deux fonctions fonctionnent indépendamment, mais je ne sais pas pourquoi elles ne fonctionneront pas ensemble. Actuellement, la deuxième fonction du code est la fonction dominante qui s'exécute tandis que l'autre est désactivée.Deux fonctions de défilement concurrentes pour ancrer les fonctions dans la même page html page

function scrollToAnchor(aid){ 
    var aTag = $("a[name='"+ aid +"']"); 
    $('html,body').animate({scrollTop: aTag.offset().top-135},'slow'); 
    } 

    $("a").click(function() { 
    var href = $(this).attr('href').replace('#', '') 
    scrollToAnchor(href); 
}); 

et le second script:

function openProject(href) { 
    //remove existing content 
    if ($("#contentBox").is(":visible")) { 
     $("#contentBox").animate({ 
      height: "0" 
     }).empty(); 
    } 
    $("#contentBox").load("projects.html " + href, function() { 
     //create map 
     var mapLat = $(this).find(".map-canvas .lat").text(); 
     var mapLon = $(this).find(".map-canvas .lon").text(); 
     var mapOptions = { 
      center: new google.maps.LatLng(mapLat, mapLon), 
      disableDefaultUI: true, 
      zoom: 16 
     }; 
     var map = new google.maps.Map($(this).find(".map-canvas")[0], mapOptions); 
     var marker = new google.maps.Marker({ 
      position: new google.maps.LatLng(mapLat, mapLon), 
      map: map 
     }); 
     //create slideshow 
     var slides = $(this).find(".flexslider"); 
     if (slides.length) { 
      slides.flexslider(); 
     } 
     //open 
     var contentBoxHeight = $(this).css("height", "950px").height(); 
     $(this).css("height", "0"); 
     $("#contentBox").animate({ 
      height: contentBoxHeight 
     }); 
     var headerHeight = 135; 
     $("html, body").animate({ 
      scrollTop: $(this).offset().top - headerHeight 
     }); 

     $(".close").on("click", function (e) { 
      $("#contentBox").empty(); 
      $("#contentBox").animate({ 
       height: 0 
      }); 
     }); 
    }); 
} 
}); 
+0

Quel est le problème spécifique que vous rencontrez? Sois plus précis. Quel est le comportement que vous obtenez? –

+0

Dans le cas illustré, le second

Questions connexes