要滚动位置设置为底部,你可以使用jQuery/JavaScript的一点点:
// maximum vertical scroll
var maxScrollV = $('#go-up')[0].scrollHeight - $('#go-up').innerHeight();
// Set vertical scroller to bottom
$('#go-up').scrollTop(maxScrollV);
至于与水平滚动条做垂直滚动,我会创建一个假的滚动它位于主要内容下方并在两个方向上制作主要内容overflow: hidden
。然后使用jQuery和一些数学使用伪造的滚动条的位置来设定主要内容的滚动位置:
$('#main').stellar();
// maximum vertical scroll
var maxScrollV = $('#go-up')[0].scrollHeight - $('#go-up').innerHeight();
// Set vertical scroller to bottom
$('#go-up').scrollTop(maxScrollV);
// Maximum horizontal scroll of fake scroller
var maxScrollH = $('#scroller')[0].scrollWidth - $('#scroller').innerWidth();
// Whenever you move the fake scroller, update the content's scroll
$('#scroller').on('scroll', function() {
// position of fake scroll bar
var sL = $('#scroller').scrollLeft();
if (sL < 3000) {
// If not at the vertical scroller, just H-scroll
$('#main').scrollLeft(sL);
} else {
// How far have we scrolled passed the vertical scroll point?
var percScrollV = (sL-3000)/(maxScrollH-3000);
// Make sure we only scroll to the vertical scroll point
$('#main').scrollLeft(3000);
// Do the vertical scroll
$('#go-up').scrollTop(maxScrollV - (maxScrollV * percScrollV));
}
});
演示:http://jsfiddle.net/JD7Jc/1/
这里我演示使用了垂直滚动条的固定位置(3000像素)和假滚动的任意宽度,但有一点点工作,你可以自动找到位置,以及根据一些合理的计算设置宽度。
编辑,这就是一个很好的例子:http://jsfiddle.net/JD7Jc/2/
这是可笑的令人印象深刻。真的不会想到我自己。不够感谢你! – richie 2013-04-03 21:03:31
不幸的是,使用这种方法后 - 我意识到你不能将滚轮方法附加到“假”滚动条....任何想法? – richie 2013-04-15 09:59:47
上面添加了演示。它使用一些基本的JavaScript事件处理,因为mousewheel事件不是跨浏览器的。有这个插件,但演示应该告诉你的基本知识:http://jsfiddle.net/SKUQB/ – 2013-04-15 22:15:56