如何使jquery noconflict这段代码

时间:2016-12-20 07:03:35

标签: jquery

请帮我把JQuery“noconflict”这段代码。 这适用于“Navbar固定滚动(带过渡)”。 这是针对导航栏的。

//Hello, world!
//This is an example to show the potential of an offcanvas layout pattern in     
//Bootstrap. Try some responsive-range viewport sizes to see it in action.


$(document).ready(function() {
    /**
     * This object controls the nav bar. Implement the add and remove
     * action over the elements of the nav bar that we want to change.
     *
     * @type {{flagAdd: boolean, elements: string[], add: Function, remove: Function}}
     */
    var myNavBar = {
        flagAdd: true,
        elements: [],
        init: function(elements) {
            this.elements = elements;
        },
        add: function() {
            if (this.flagAdd) {
                for (var i = 0; i < this.elements.length; i++) {
                    document.getElementById(this.elements[i]).className += " fixed-theme";
                }
                this.flagAdd = false;
            }
        },
        remove: function() {
            for (var i = 0; i < this.elements.length; i++) {
                document.getElementById(this.elements[i]).className = document
                    .getElementById(this.elements[i]).className.replace(/(?:^|\s)fixed-theme(?!\S)/g, '');
            }
            this.flagAdd = true;
        }
    };
    /**
     * Init the object. Pass the object the array of elements
     * that we want to change when the scroll goes down
     */
    myNavBar.init(["header", "header-container", "brand"]);
    /**
     * Function that manage the direction
     * of the scroll
     */
    function offSetManager() {
        var yOffset = 0;
        var currYOffSet = window.pageYOffset;
        if (yOffset < currYOffSet) {
            myNavBar.add();
        } else if (currYOffSet == yOffset) {
            myNavBar.remove();
        }
    }
    /**
     * bind to the document scroll detection
     */
    window.onscroll = function(e) {
            offSetManager();
        }
        /**
         * We have to do a first detectation of offset because the page
         * could be load with scroll down set.
         */
    offSetManager();
});

0 个答案:

没有答案