5

请帮助我使用 iscroll 滚动固定列表项。我正在做一个项目,我想使用 iscroller 一次滚动三个 LIST 项目。我已经尝试使用 iscroller 的 scrollTo、ScrollToPage、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>
4

1 回答 1

2

如果我得到它正确,你想在 iscroll 窗口中捕捉每个第三个项目。

我想不出任何优雅的方式来做到这一点(不确定是否有一个选项允许在捕捉之前设置要忽略的元素数量)

但是您可以(取决于您修改标记的灵活性)将这三个元素作为每个“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

        });

希望有帮助。

干杯瓦林德

于 2013-12-17T02:14:21.263 回答