[英]Remove :first-child from sidebar of titles when scrolling
I've wrote a script that appends a div to a sidebar when an article is scrolled to on the page, the div simply contains the title of the article that is loaded in. This is a part of an infinite scroll functionality that I have been building for a news website. 我编写了一个脚本,该脚本在页面上滚动到页面时将div附加到侧边栏,该div仅包含加载的文章的标题。这是我一直使用的无限滚动功能的一部分建立新闻网站。
The issue I have ran into during testing is; 我在测试过程中遇到的问题是; when the user scrolls to an article quite far down the page, my sidebar begins to contain a lot of titles, so I'm looking to eliminate the :first-child
when the sidebar contains 10 child divs (titles). 当用户滚动到页面下方很远的文章时,我的侧边栏开始包含很多标题,因此当侧边栏包含10个子div(标题)时,我希望消除:first-child
。
jQuery: jQuery的:
if(($('#sideArticles').children().size()) > 10){
var del = $('#sideArticles').find(':first-child');
$('#sideArticles').remove(del);
}
Nothing is happening, nor am I receiving any errors from the console. 什么也没发生,我也没有从控制台收到任何错误。 If anyone could shed some knowledge that'd be much appreciated. 如果有人能流传一些知识,将不胜感激。
Cheers, Rich. 干杯,富有。
I would try this: 我会尝试这样的:
if(($('#sideArticles').children().size()) > 10){
var del = $('#sideArticles').children().eq(0);
del.remove();
}
There is not enough code to really do testes but this could work : 没有足够的代码来真正做睾丸,但这可以工作:
if(($('#sideArticles').children().size()) > 10){
var del = $('#sideArticles').children().eq(0);
del.remove();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.