问题
I have 2 lists and I use iScroll for vertical scrolling.
The second list is inside the first list.
When I scroll the second list, the first list is also scrolling.
I want that when I scroll the inside list (the second list), the main list (the first list) will not scroll.
How can I do that?
Here is an Example:
<div id="wrapper" style="overflow: hidden;">
<div id="scroller">
<ul id="thelist">
<li>Pretty row 1</li>
<li>Pretty row 2</li>
<li>Pretty row 3</li>
<li>Pretty row 4</li>
<li>Pretty row 5</li>
<li>Pretty row 6</li>
<li id='inWarper'>
<div id="scroller">
<br/>
<ul>
<li>Pretty row 1</li>
<li>Pretty row 2</li>
<li>Pretty row 3</li>
<li>Pretty row 4</li>
<li>Pretty row 5</li>
<li>Pretty row 6</li>
<li>Pretty row 7</li>
<li>Pretty row 8</li>
<li>Pretty row 9</li>
<li>Pretty row 10</li>
</ul>
</div>
</li>
<li>Pretty row 7</li>
<li>Pretty row 8</li>
<li>Pretty row 9</li>
<li>Pretty row 10</li>
<li>Pretty row 11</li>
<li>Pretty row 12</li>
<li>Pretty row 13</li>
<li>Pretty row 14</li>
<li>Pretty row 15</li>
<li>Pretty row 16</li>
<li>Pretty row 17</li>
<li>Pretty row 18</li>
</ul>
<br/>
</div>
</div>
And in Load event:
myScroll = new iScroll('wrapper');
myScroll2 = new iScroll('inWarper');
CSS:
#scroller ul {
list-style: none;
padding: 0;
margin: 0;
width: 100%;
text-align: left;
}
#scroller {
position: absolute;
z-index: 1;
/* -webkit-touch-callout: none; */
-webkit-tap-highlight-color: rgba(0,0,0,0);
width: 100%;
padding: 0;
}
#wrapper {
position: absolute;
z-index: 1;
top: 45px;
bottom: 48px;
left: 0;
width: 100%;
background: #aaa;
overflow: auto;
height:150px;
}
#inWarper {
color:red;
position: absolute;
z-index: 1;
height:100px;
left: 0;
width: 100%;
background: #aaa;
overflow: auto;
}
JSFiddle: http://jsfiddle.net/PPtWs/64/
回答1:
The idea to fix this problem is to prevent (stop) propagation of the scrolling firing event to the parent div
This is how to fix it
myScroll = new iScroll('wrapper');
myScroll2 = new iScroll('inWarper' , {
onBeforeScrollStart : function(e) {
e.stopPropagation();
}});
Example http://jsfiddle.net/khaledalyawad/4p7t8ymp/
来源:https://stackoverflow.com/questions/24283119/iscroll-inside-iscroll-nested-iscroll-unexpected-behavior