jquery基于DIV指定区域局部滚动定位特效代码

所属分类: 网页特效-导航菜单    2023-11-16 10:23:39

jquery基于DIV指定区域局部滚动定位特效代码 ie兼容6

jquery基于DIV指定区域局部滚动定位特效代码(共3个文件)

    • index.html

使用方法

(function ($) {
    'use strict';

    let defaults = {
        activeClass: 'active',
        fixed: true
    };

    let container,
        target,
        activeClass,
        fixed,
        collection = [];

    let init = function (params) {
        let options = $.extend({}, defaults, params);

        container = this;
        target = options.target;
        activeClass = options.activeClass;
        fixed = options.fixed;

        let hash = null, element = null;
        $.each(target, function () {
            (hash = this.href.split('#')[1]) !== undefined
                ? (element = container.find(`[id="${hash}"]`)).length > 0 ? collection.push({
                    link: $(this),
                    element: element
                }) : null : null;
        });
        this.unbind('scroll', eventListener).bind('scroll', eventListener);
        return this;
    };

    let eventListener = function () {
        let relativeOffsetTop = collection.length > 0 ? collection[0].element.offset().top + container.scrollTop() : 0;
        $.each(collection, function () {
            let _ot = Math.floor(this.element.offset().top + container.scrollTop() - relativeOffsetTop);
            let _st = Math.ceil(container.scrollTop());
            if (_ot <= _st && _st < _ot + Math.floor(this.element.outerHeight())) {
                if (!this.link.hasClass(activeClass)) {
                    target.removeClass(activeClass);
                    this.link.addClass(activeClass);
                }
                return false;
            } else if (fixed) {
                this.link.removeClass('active');
            }
        });
    };

    $.fn.scrollSpy = function (options) {
        if (typeof options === 'object' && typeof options.target != "undefined") {
            return init.apply(this, arguments);
        } else {
            $.error('You should use plugin with required options...');
        }
    };

})(jQuery);

相关资源 / 导航菜单

jquery精仿京东商城导航菜单源码

一款红色风格的横向二级导航,展开的二级导航模块带关闭按钮。
  导航菜单
 58  

jquery图标导航鼠标滑过类似气泡放大缩小显示二级导航菜单

鼠标hover经过气泡动画放大特效,并且显示下级导航菜单,很有创意的设计!
  导航菜单
 57  

jquery右侧边固定层导航菜单依次动画滑动显示菜单展开

jquery右侧边固定层导航菜单依次动画滑动显示菜单展开
  导航菜单
 42  

jquery竖直倾斜导航条鼠标悬停导航条背景滑动显示

一款企业网站蓝色风格导航菜单,倾斜式另类创意导航条。
  导航菜单
 68  

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论