简体   繁体   English

如何根据星期几将页面滚动到某个班级?

[英]How to make page scroll to certain class depending on day of the week?

I want a WP page to scroll to certain class according to day of the week. 我希望WP页面根据星期几滚动到特定班级。 On each day I want the users browsers to scroll to the current day and on Sunday to go to Monday. 我希望用户浏览器每天都滚动到当天,而星期日则转到星期一。

HTML added to a WordPress page HTML已添加到WordPress页面

<h2>Activities</h2>
<ul>
   <li><span class="monday">Monday</span>xyz</li>  
   <li><span class="tuesday">Tuesday</span>xyz</li>
   <li><span class="wednesday">Wednesday</span>xyz</li>
   <li><span class="thursday">Thursday</span>xyz</li>
   <li><span class="friday">Friday</span>xyz</li>
   <li><span class="saturday">Saturday</span>xyz</li>    
</ul> 

I know I need the getDay JS to determine the current day, but I have a hard time getting the page to scroll. 我知道我需要getDay JS来确定当前日期,但是我很难让页面滚动。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance! 提前致谢! vik3d vik3d

See if this helps: https://jsfiddle.net/y3llowjack3t/rephuby3/ 看看是否有帮助: https : //jsfiddle.net/y3llowjack3t/rephuby3/

$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $(".wednesday").offset().top
    }, 2000);
});

See this link for more help on the subject: jQuery scroll to element 请参阅此链接以获取有关该主题的更多帮助: jQuery滚动到元素

Update: 更新:

To scroll on load see: https://jsfiddle.net/y3llowjack3t/rephuby3/1/ 要在负载上滚动,请参见: https : //jsfiddle.net/y3llowjack3t/rephuby3/1/

To scroll based on weekday name: https://jsfiddle.net/y3llowjack3t/rephuby3/3/ 要根据工作日名称滚动: https : //jsfiddle.net/y3llowjack3t/rephuby3/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM