我正在使用Bootstrap的滾動成功,但我想在目標錨點水平級聯的頁面上使用它。我已經調整到無濟於事,無法實現它的工作。我也試過https://gist.github.com/marcoleong/1922743沒有成功。Bootstrap水平滾動?
請參閱我在http://jsfiddle.net/AzSWV/2/小提琴與呼叫工程$('body').scrollspy();
開始,您可以看到垂直scrollspy作品。 取消註釋CSS並更新小提琴以查看水平佈局。
我正在使用Bootstrap的滾動成功,但我想在目標錨點水平級聯的頁面上使用它。我已經調整到無濟於事,無法實現它的工作。我也試過https://gist.github.com/marcoleong/1922743沒有成功。Bootstrap水平滾動?
請參閱我在http://jsfiddle.net/AzSWV/2/小提琴與呼叫工程$('body').scrollspy();
開始,您可以看到垂直scrollspy作品。 取消註釋CSS並更新小提琴以查看水平佈局。
通過更換解決這個所有出現的top
或Top
分別爲left
或Left
,並分別用height
或Height
分別替換爲width
或Width
。我也改變了目標元素。
我成功地做到這一點,而不使用內置的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();
});
「沒有看到我的代碼」?我發佈了一個小提琴,隨時更新或分叉! – cfx
@gordian我的意思是..這顯然是你的小提琴的填充內容..沒有你的具體代碼 – haxxxton