;(function($) { $.fn.scrollHighlight = function(options) { return this.each(function() { var defualts = { childItem: "a", //高亮的节点 attribute: "href", //高亮节点属性 highlight: 'highlight', //给高亮节点添加的类 buffer: 0, //距离节点的距离 container: window, //滚动内容的盒子,默认是window cancelFlag: true, //当超过节点时是否取消高亮,默认是取消高亮 mode: 'vertical' //滚动的模式,默认为竖直方向,可以为其他如horizontal(水平方向) }; var opts = $.extend({}, defualts, options), obj = $(this), $container = $(opts.container), mode = opts.mode, buffer = opts.buffer, highlight = opts.highlight, childItem = opts.childItem, attribute = opts.attribute; if (obj.length <= 0) return; var resizeTimer; // Set resizeTimer to empty so it resets on page load var item = obj.find(childItem), i = 0, len = item.length, wrap = [], index = [], anchor = []; for (; i < len; i++) { anchor.push(item.eq(i).attr(attribute)); //获取需要高亮的所有节点 } var aLen = anchor.length; for (var j = 0; j < aLen; j++) { var that = opts.container == window ? $(document).find(anchor[j]) : $container.find(anchor[j]); if (that.length && that.is(":visible")) { //筛选出容器内存在的节点并且是显示的 wrap.p
JQ 滚动高亮节点插件
最新推荐文章于 2023-06-29 16:20:18 发布