大佬教程收集整理的这篇文章主要介绍了jquery – 在基于当前视图使用scrollto时突出显示活动链接,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是:我想在主菜单中显示活动链接.因此,如果您滚动到联系表单,则突出显示联系人链接.现在,我可以通过在单击后添加类来在jquery中执行此操作.如果这样做,如果用户要手动滚动到另一个部分,联系人链接仍然是活动的,这将是不正确和误导.
所以我的想法是以某种方式解决当前正在查看哪个div id.我真的不明白怎么做.有任何想法吗?
$(function(){ var sections = {},_height = $(window).height(),i = 0; // Grab positions of our sections $('.section').each(function(){ sections[this.name] = $(this).offset().top; }); $(document).scroll(function(){ var pos = $(this).scrollTop(); // Look in the sections object and see if any section is viewable on the screen. // If two are viewable,the lower one will be the active one. for(i in sections){ if(sections[i] > pos && sections[i] < pos + _height){ $('a').removeClass('active'); $('#nav_' + i).addClass('active'); } } }); });
以上是大佬教程为你收集整理的jquery – 在基于当前视图使用scrollto时突出显示活动链接全部内容,希望文章能够帮你解决jquery – 在基于当前视图使用scrollto时突出显示活动链接所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。