大佬教程收集整理的这篇文章主要介绍了事件 – jQuery能否确定当前用户浏览器视图中的哪些div?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$(document).scroll(function() { var $this = $(this),scrollTop = $this.scrollTop(),// find the section next to the current scroll top sections = $(this).find('section'),topSection = null,minDist = Infinity; sections.each(function() { // calculate top and bottom offset of the section var top = $(this).offset().top,bottom = top + $(this).innerHeight(),// only use the minimum distance to the scroll top relativeDistance = Math.min( Math.abs(top - scrollTop),Math.abs(bottom - scrollTop) ); // in case the distance is smaller than // the prevIoUs one's replace it if (relativeDistance < minDist) { minDist = relativeDistance; topSection = this; } }); // flip the 'top' class from current to Now next one $('section.top').removeClass('top'); $(topSection).addClass('top'); });
你可以在Play Webframework’s Homepage看到一个非常好的例子
如果这不是您想要的,您可以观察任何元素的完整偏移或位置,并使用$(window).innerWidth()或$(window).innerHeight()将其与当前视口进行比较.
以上是大佬教程为你收集整理的事件 – jQuery能否确定当前用户浏览器视图中的哪些div?全部内容,希望文章能够帮你解决事件 – jQuery能否确定当前用户浏览器视图中的哪些div?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。