2013-05-10 72 views
1

我有此代码的工作...我可以使用iScroll来scrollToElement + offset吗?

myScroller.scrollTo(0, -654, 200); 

我也有这方面的工作....

myScroller.scrollToElement("#p4", "1s"); 

有没有一种方法来添加偏移到#ID,像scrollToElement(“# p4“+ 100,”1s“)?

+0

@Layne ..你使用Iscroll哪个版本的100个像素。对我来说myScroller.scrollToElement(“#p4”,“1s”);不管用。我正在使用Iscroll Lite版本。 – 2014-01-20 04:25:47

回答

1

不,你不能。

myScroller.scrollToElement("#p4", "1s"); 

因为第一个参数应该是DOM元素的CSS选择器。因此,您可以使用"#p4" + 100来应用CSS规则吗?如果你的答案是YES,那么你也可以不。

如果您想在特定时间后滚动到下一个元素,可以使用nth-child() CSS属性尝试使用适当的超时和增量标志。像这样的东西(假设你的元件是将具有ID myDiv父DIV元素中)

var incre = 0; 
function customScrollToElement(){ 
    myScroller.scrollToElement("#myDiv:nth-child(" + incre + ")", 10); 
    incre ++; 
} 
setTimeout(function(){ 
    customScrollToElement(); 
},100); 
1

您可以先使用jQuery获取元素的position相对于他们的父母有一些计算做。

var left = -1 * ($('#p4').position().left + 100), 
    top = -1 * ($('#p4').position().top); 
myScroller.scrollTo(left, top, 1000); 

这将向右滚动元件

相关问题