每天轮换列表项 jquery

Rotate through list items per day jquery

本文关键字:jquery 列表 每天      更新时间:2023-09-26

我正在尝试每天显示一个列表项,当列表到达末尾时,我希望它转到开头,这个 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();
如果要

每天显示一个列表项,并在第二天显示下一个列表项:

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