2010-12-20 42 views
0

我已經下載了jquery滾動腳本(http://www.position-absolute.com/articles/better-html-anchor-a-jquery-script-to-slide-the-scrollbar/),它將滾動到您的當你點擊一個鏈接時錨點。但是,我想知道是否有任何方法可以使用php/jquery從URL中獲取項目ID,然後在頁面加載時滾動到該項目ID?jquery觸發錨點頁面加載滾動?

這裏的滾動JS:

$(document).ready(function() { 
    $("a.anchorLink").anchorAnimate() 
}); 

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

下面是它的一個示例URL與商品ID:(?使用PHP我相信)

http://www.somesite.com/index.php?view=list&itemid=3 

^^所以基本上我需要的itemid抓住和然後告訴jQuery滾動到該錨點:

<a name="3" id="3"></a> 

任何幫助將不勝感激:)

回答