扫码关注官方订阅号
滚动到达第几块内容相应的右边也会选中第几个
认证高级PHP讲师
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Welcome!</title> <style> ul { position: fixed; right: 30px; top: 100px; } .red { color: red; } </style> </head> <body> <h1>title1</h1> <p style="height:300px;"></p> <h1>title2</h1> <p style="height:300px;"></p> <h1>title3</h1> <p style="height:300px;"></p> <h1>title4</h1> <p style="height:300px;"></p> <h1>title5</h1> <p style="height:300px;"></p> <h1>title6</h1> <p style="height:300px;"></p> <h1>title7</h1> <p style="height:300px;"></p> <h1>title8</h1> <p style="height:300px;"></p> <ul> <li>111111</li> <li>222222</li> <li>333333</li> <li>444444</li> <li>555555</li> <li>666666</li> <li>777777</li> <li>888888</li> </ul> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script> var timeout; $(window).on("scroll", function() { var self = $(this); if (timeout) window.clearTimeout(timeout); timeout = setTimeout(function () { var st = self.scrollTop(); var index = 0; $("h1").each(function() { if (st < $(this).offset().top) { index = $("h1").index($(this)) - 1; return false; } }); $("ul>li").removeClass('red').eq(index).addClass('red') }, 100); }) </script> </body> </html>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
认证高级PHP讲师