2013-04-01 79 views

回答

1

通過更換解決這個所有出現的topTop分別爲leftLeft,並分別用heightHeight分別替換爲widthWidth。我也改變了目標元素。

http://jsfiddle.net/AzSWV/19/

-1

我成功地做到這一點,而不使用內置的scrollspy方法白手起家從這個簡約的垂直滾動間諜服用參考:http://jsfiddle.net/mekwall/up4nu/

沒有看到你的[實際]代碼我不能真正改變了我的價值觀專門爲你,但它不應該是太難用這個工作:

$(document).ready(function(){ 
    var lastId; 
    //change this selector to the section containing your menu items 
    var pickerMenu = $("#sliderInner"); 
    var menuItems = pickerMenu.find("a"); 
    //finds the anchors to be linked to 
    var scrollItems = menuItems.map(function(){ 
     var item = $($(this).attr("href")); 
     if(item.length){ return item; } 
    }); 

    //if you are scrolling the body rather than an overflow div change #main to body 
    $('#main').scroll(function(){ 
     var currentItem = scrollItems.map(function(){ 
      //currently uses center of the screen as active location 
      //feel free to place the $(window) section with 0 to go from left 
      //or remove the the /2 to have from the right 
      if($(this).offset().left < ($(window).width()/2)){ 
       return this; 
      } 
     }); 
     currentItem = currentItem[currentItem.length - 1]; 

     var id = currentItem && currentItem.length ? currentItem[0].id : ""; 
     if (lastId !== id) { 
      lastId = id; 

     //adds the class 'active' to the parent of the link 
     menuItems 
      .parent().removeClass("active") 
      .end().filter("[href=#"+id+"]").parent().addClass("active"); 
     } 
    }); 
    //set first item to active 
    menuItems.first().parent().addClass("active"); 
}); 

編輯: 按您的要求與您的測試數據更新您的提琴http://jsfiddle.net/AzSWV/12/

EDIT2: 你可能要包括一些方便,向下滾動左右滾動的東西..有退房布蘭登·艾倫的jQuery的鼠標滾輪在https://github.com/brandonaaron/jquery-mousewheel插件上並將其與此相結合:

$("#main").mousewheel(function(e, delta) { 
    this.scrollLeft -= (delta * 50); 
    e.preventDefault(); 
}); 
+0

「沒有看到我的代碼」?我發佈了一個小提琴,隨時更新或分叉! – cfx

+1

@gordian我的意思是..這顯然是你的小提琴的填充內容..沒有你的具體代碼 – haxxxton