检测可滚动下拉的结束 [英] detecting the end of the scrollable drop down
问题描述
我正在动态生成一个选择选项框。可以有任意数量的选项。当用户向下滚动到框的末尾时,我需要触发一个事件,(我将调用服务器并使用更多选项填充选择)。它就像创建一个分页一样,但是在下拉框中。
I am generating a select option box dynamically. There can be any number of options. When the user scrolls down to the end of the box, I need to trigger an event, (where I will call the server and populate the select with more options). Its like creating a pagination, but in dropdown box.
有人可以告诉我这是怎么做的。
Can anybody tell me how can this be done.
因此,当用户滚动到下拉列表的末尾时,我唯一需要的是触发事件。多数民众赞成
So the only thing I need is to trigger an event, when user scrolls to the end of the dropdown. Thats all
<select style="height: 30px;line-height:30px;" class="scroll">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select>
请不要担心我将如何使用选项填充选择框,因为我正在使用meteorJs,我会很容易实现它。
Please don't worry about how I am gonna populate the select box with option, as I am using meteorJs, that I will achieve it easily.
唯一的要求是发起一个事件。
The only requirement is to fire an event.
推荐答案
你可以尝试这个,我已经创建了一个关于这个的演示,并在列表底部滚动时生成一个弹出窗口。
you can try this one, i have created a demo regarding this and generate a popup while scroll at the bottom of list.
工作小提琴演示: https://jsfiddle.net/j68o44Ld/
<div class="subtask-li">
<span class="main-tlist">
<span class="icon-taskListing"></span>
<span class="subselectedList">Default</span>
<span class="icon-subcaret"></span> </span>
<ul class="subtask-pick">
<li><a href="javascript:;">General issues</a></li>
<li><a href="javascript:;">Default</a></li>
<li><a href="javascript:;">Android Games Issues</a></li>
<li><a href="javascript:;">pt issues</a></li>
<li><a href="javascript:;">Server Development</a></li>
<li><a href="javascript:;">Resource Integration</a></li>
<li><a href="javascript:;">Server Infrastructure</a></li>
</ul>
</div>
$(document).on("click",".main-tlist",function(){
$('.subtask-pick').toggle();
});
$('.subtask-pick').scroll(function () {
if ($(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight()) {
alert("end of scroll");
// You can perform as you want
}
});
.subtask-li {
border: 1px solid #dfe8f1;
cursor: pointer;
position: relative;
background: rgba(0, 0, 0, 0) linear-gradient(to bottom, rgba(255, 255, 255, 1) 0%, rgba(246, 246, 246, 1) 100%) repeat scroll 0 0;
border-radius: 3px;
float: left;
left: 5px;
padding: 5px;
top: 6px;
}
.subtask-pick{
background-clip: padding-box;
background-color: #fff;
border: 1px solid #dfe8f1;
border-radius: 3px;
box-shadow: 0 1px 7px 2px rgba(135, 158, 171, 0.2);
display: none;
list-style: outside none none;
padding: 0 0 10px;
position: absolute;
z-index: 9;
float: left;
width: 220px;
list-style: outside none none; height:220px; overflow:auto;
}
.icon-taskListing {
display: inline-block;
vertical-align: middle;
}
.subselectedList {
overflow: hidden;
padding: 0 5px;
text-overflow: ellipsis;
white-space: nowrap;
width: 116px;
}
ul.subtask-pick li {
float: none;
display: block;
clear: both;
position: relative;
}
ul.subtask-pick li a {
padding: .9em 1em .9em .8em;
position: relative;
clear: both;
cursor: pointer;
display: block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
ul.subtask-pick li a:hover {
background: none repeat scroll 0 0 #eff4f6;
cursor: pointer;
}
a {
text-decoration: none;
outline: 0;
color: #4c4c4c;
}
这篇关于检测可滚动下拉的结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!