简体   繁体   English

iScroll不显示滚动条,但可以拖动内容

[英]iScroll doesn't show the scrollbar but lets me drag the content

This is how I call it 这就是我所说的

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));
    });
});

I modified it a little bit so you can use it with a class and not only id. 我对其进行了一些修改,以便您可以将其与类一起使用,而不仅限于id。

It seems to work (to be enabled) because I can drag the container and its content ( but it wont keep position , it will restore on mouse release ) 它似乎有效(启用),因为我可以拖动容器及其内容( 但不会保持位置 ,它将在鼠标释放时恢复)

If you want to see it happening please visit http://toniweb.us/grano and click on any item in the menu, the new shown has the effect. 如果您想查看它的发生,请访问http://toniweb.us/grano并单击菜单中的任何项目,新显示的内容即会生效。

Any idea why it is working but not as expected? 知道为什么它起作用但未达到预期效果吗?

The reason I want to do this is because the container has several subcontainers that will be hidden or shown depending on the content selection. 我之所以要这样做,是因为容器具有多个子容器,这些子容器将根据内容选择而隐藏或显示。

CSS: 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;
    }

I had a look at your code on: http://toniweb.us/grano 我在以下网址上查看了您的代码: http//toniweb.us/grano

I think what you would like to do is use iScroll on your class with "scrolling". 我认为您想做的是在班级上使用“滚动”功能使用iScroll。 That is not what you are doing in the following code but instead you are actually setting iScroll to use the parent of your scroller DIV: 那不是您在以下代码中所做的,而是实际上是在将iScroll设置为使用滚动条DIV的父级:

id = $(this).attr('id');
$(this).html('<div class="scroller">'+$(this).html()+'</div>');
myScroll.push(new iScroll(id));

For reference: iScroll uses an ID rather than a class 供参考:iScroll使用ID而不是类

The effect this is having is that it is causing the "snap" effect on the immediately following block level element - your scroller DIV. 这样做的效果是,它会在紧随其后的块级元素(滚动条DIV)上引起“快照”效果。

Consider this example where there is a DIV (id="scroller") containing an OL which contains a number of (block level) LIs: 考虑下面的示例,其中有一个DIV(id =“ scroller”)包含一个OL,该OL包含许多(块级别)LI:

http://cubiq.org/dropbox/iscroll4/examples/simple/ http://cubiq.org/dropbox/iscroll4/examples/simple/

Long story short, give your DIV with the scroller class an id and create your iScroll from that instead. 长话短说,给您的DIV加上scroller类一个ID,然后从中创建iScroll。

if you set the style on the div tag you put the scroller on to (example) 如果您在div标签上设置style ,则将滚动条置于(示例)上

style="position:relative;overflow: hidden;height:350px;

i think it's setting the height explicitly that should solve the dragging problem 我认为这是明确设置高度,应该可以解决拖动问题

Don't you just want: 你不只是想要:

.content {overflow-y:scroll;}

Is that not what you're saying mate? 那不是你所说的伴侣吗?

The elements within the scroll div can't be floating. 滚动div中的元素不能浮动。 If they are floating and not cleared the flow of the page will mean your scrolling div is not the correct height. 如果它们浮动且未清除,则页面流程将意味着您的滚动div高度不正确。 Try avoiding any floats within your scrolling and div and see how that goes. 尝试避免在滚动和div中出现任何浮点,然后看看效果如何。 This was the problem for me. 这是我的问题。

I also found Matthews answer to be helpful as I was also calling iscroll on the wrong div. 我还发现Matthews的答案很有帮助,因为我还在错误的div上调用了iscroll。 I think the confusing thing about the iScroll example is that it's easy to assume iScroll is called on the div with the ID scroller, but it's called on the wrapper div. 我认为关于iScroll示例的令人困惑的事情是,很容易假设使用ID滚动条在div上调用了iScroll,但是在包装div上调用了iScroll。 The div with the ID scroller doesn't actually need an ID and I think for the examples sake this would be clearer without that. 带有ID滚动条的div实际上并不需要ID,我认为出于示例的考虑,没有该ID会更清楚。 eg 例如

<div id="wrapper">
    <div>
         <p>Whatever you want here</p>
         <ul>
             <li>1</li>
         </ul>
    </div>
</div>
...
myScroll = new iScroll('wrapper');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM