这就是我所说的
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
/**/
$(document).ready(function() {
//Created an array for adding n iScroll objects
var myScroll = new Array();
$('.content').each(function(){
if($(this).attr('id')==null){
$(this).attr('id') = $(this).attr('class');
}
id = $(this).attr('id');
console.log(id);
$(this).html('<div class="scroller">'+$(this).html()+'</div>');
myScroll.push(new iScroll(id));
});
});
我对其进行了一些修改,以便您可以将其与类一起使用,而不仅限于id。
它似乎有效(启用),因为我可以拖动容器及其内容(但不会保持位置,它将在鼠标释放时恢复)
如果您想看到它发生了,请访问http://toniweb.us/grano并单击菜单中的任何项目,新显示的内容即会生效。
知道为什么它起作用但未达到预期效果吗?
我之所以要这样做,是因为容器具有多个子容器,这些子容器将根据内容选择而隐藏或显示。
CSS:
#nvl1{
padding:0px 25px;
z-index:10;
position:absolute;
left:0px;
background:url("../img/fondoNivel2.jpg") no-repeat scroll right 0 #79797B ;
height:100%;
}
#nvl1 .content{
width:650px;
z-index:11;
display:none;
color:#6666b6b;
position:relative;
line-height:30px;
}
最佳答案
我在以下代码上查看了您的代码:
我想您想做的是在班级上使用“滚动”的iScroll。那不是您在以下代码中所做的,而是实际上是在将iScroll设置为使用滚动条DIV的父级:
id = $(this).attr('id');
$(this).html('<div class="scroller">'+$(this).html()+'</div>');
myScroll.push(new iScroll(id));
供参考:iScroll使用ID而不是类
这样做的效果是,它会在紧随其后的块级元素(滚动条DIV)上引起“快照”效果。
考虑下面的示例,其中有一个DIV(id =“ scroller”)包含一个OL,该OL包含多个(块级别)LI:
http://toniweb.us/grano
长话短说,给您的DIV加上滚动器类一个ID,然后从中创建您的iScroll。
关于javascript - iScroll不显示滚动条,但可以拖动内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8166443/