2014-05-21 19 views
0

兩個函數獨立工作,但我不知道他們爲什麼不能一起工作。目前,無論代碼中的第二個函數是否爲主要函數,都會在另一個被禁用時運行。兩個競爭的滾動功能錨定功能在同一頁html頁

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); 
}); 

和第二個腳本:

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

您遇到的具體問題是什麼?更加詳細一些。你得到的行爲是什麼? –

+0

在所示情況下,第二個