首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每天轮换列表项jquery

问每天轮换列表项jquery
EN

Stack Overflow用户
提问于 2016-03-23 10:26:48
回答 1查看 57关注 0票数 0

我尝试每天显示一个列表项,当列表到达末尾时,我希望它转到开头,这就是我正在使用的javascript。

代码语言:javascript
复制
     // Get the number of the week since the epoch.
var day = Math.floor(new Date().getTime() / (1000 * 60 * 60 * 24 * 7 * 1));

i = 0;
// Show one div per day.
$('#postTips li').hide();
$('#postTips li ') + (i = ++i % day)).show();
EN

回答 1

Stack Overflow用户

发布于 2016-03-23 10:41:39

如果您希望一天显示一个列表项,第二天显示下一个列表项:

代码语言:javascript
复制
var day = 0, list_items = $('#postTips li'), current_list_item = 0, total_list_item = list_items.length;
function update_list_item() {
    var day_new = Math.floor(new Date().getTime() / (1000 * 60 * 60 * 24 * 1));
    if (day_new > day) {
        day = day_new;
        list_items[current_list_item].style.display='none';
        list_items[current_list_item=day%total_list_item].style.display='list-item';
    }
    requestAnimationFrame (update_list_item);
}
list_items.hide ();
update_list_item ();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36168736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档