请帮我用iscroll滚动固定列表项。我正在开发一个项目,我想使用iscroller一次滚动三个LIST项目。我已经尝试使用scrollTo,ScrollToPage,iscroller的ScrollToElement函数滚动,但它对我不起作用所以请帮我滚动固定长度项目一次用户滚动。我正在使用android项目,我正在使用iscroll4来滚动元素。
我的凯德就像这样......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
.span8{
position: absolute;
width:630px;
height:100px;
overflow:auto;
}
.menu{
float:left;
width:200px;
height:100px;
background-color:red;
margin-left:10px;
}
#scroller{
width:3000px;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="js/libs/iscroll.js" type="text/javascript"></script>
<script>
var isScrolling = false;
myScroll = new iScroll('headerWrapper',{
snap: 'li',ome Wor
hScrollbar: false,
vScrollbar: false ,
momentum: true,
vScroll: false,
onScrollMove : function(e){
// clearHeaderInterval();
// myScroll.scrollTo(50, 0);
// myScroll.refresh();
console.log('onScrollMove===============>>>>>>>>>>>>>');
isScrolling = true;
// here get the device type and version
if(deviceType() == 'android'){
var deviceVersion = device.version;
console.log(" deviceType is ===>>"+deviceVersion);
if(deviceVersion=='4.1' || deviceVersion=='4.1.1'|| deviceVersion=='4.1.2'){
console.log("android version is ===>>"+deviceVersion);
setTimeout(function(){
myScroll.refresh(); }, 1000);
}
}
// setTimeout(function(){myScroll.refresh();},0);
},
});
</script>
</head>
<body>
<div class="span8 marginleft mid-menu-panel" id="headerWrapper">
<div id="scroller">
<ul id="tabitems">
<li class="dropdown-toggle menu click_h" id="home">
Home
</li>
<li class="dropdown-toggle menu click_h" id="word" >
Word
</li>
<li class="dropdown-toggle menu click_h" id="sentences">
Sentence
</li>
<li class="dropdown-toggle menu click_h" id="icon">
Icon
</li>
<li class="dropdown-toggle menu click_h" id="question">
Question
</li>
<!--<li class="dropdown-toggle menu click_h" id="write_words">-->
<!--Write-->
<!--</li>-->
<li class="dropdown-toggle menu click_h" id="level" >
Level
</li>
<li class="dropdown-toggle menu click_h" id="config/" >
Configuration
<li class="dropdown-toggle menu click_h" id="info" >
Info
</li>
</li>
<li class="dropdown-toggle menu click_h" id="website">
Web Services
</li>
<li class="dropdown-toggle menu click_h" id="help" >
Help
</li>
<!--td width="20">
<div class="buttons next">
<button class="btn btn-large right_arrow" type="button">
<i class="icon_right_arrow"></i>
</button>
</div></td-->
</ul>
</div>
</div>
</body>
</html>
答案 0 :(得分:2)
如果我正确地获取它,你想要在iscroll窗口中捕捉每个第3项。
我想不出任何优雅的方法(不确定是否有一个选项允许在捕捉之前设置要忽略的元素数量)
但是你可以(取决于你稍微修改一下标记的灵活性)将这三个元素作为每个“li”的子元素移动。
继承js fiddle(http://jsfiddle.net/QFz3L/1/)
的链接HTML / CSS / JS。
CSS和JS之间没有太大区别,只是HTML的一些改动
HTML:
<div class="span8 marginleft mid-menu-panel" id="headerWrapper">
<ul id="scroller">
<li class="menu">
<div>block 1</div>
<div class="cf">
<div class="span3">
item 1
</div>
<div class="span3">
item 2
</div>
<div class="span3">
item 3
</div>
</div>
</li>
<li class="menu">
<div>block 2</div>
<div class="cf">
<div class="span3">
item 4
</div>
<div class="span3">
item 5
</div>
<div class="span3">
item 6
</div>
</div>
</li>
<li class="menu">
<div>block 3</div>
<div class="cf">
<div class="span3">
item 7
</div>
<div class="span3">
item 8
</div>
<div class="span3">
item 9
</div>
</div>
</li>
</ul>
</div>
CSS:
.cf {
overflow:hidden;
}
.span3 {
float:left;
height:100px;
background:green;
width:210px;
}
.span8{
position: absolute;
width:630px;
height:100px;
}
.menu{
float:left;
width:630px; /* same as parent( .span8 ) to make sure only 1 .menu is visible ofc */
height:100px;
background-color:red;
}
#scroller{
width:1890px; /* total width of children, 630 * 3 */
overflow:hidden;
list-style:none;
padding:0;
margin:0;
}
JS:
myScroll = new iScroll('headerWrapper',{
snap: 'li',
hScrollbar: false,
vScrollbar: false ,
momentum: true,
vScroll: false
});
希望有所帮助。
干杯 Varinder