PageSourceSearch

https://vinlonginox.vn/js/mnfixed/mnfixed.js

js vinlonginox.vn collected 2026-10-07 21:06:45 UTC 8,012 bytes, 234 lines download raw bytes

1/*
2===============================
3============MNFIXED============
4===============================
5      Version: 2.0.1
6       Author: Hoang Minh Ngoc
7Date Publish : 13/05/2019
8*/
9(function($){
10    class mnfixed{
11        constructor(ele,opt){
12            this.ele = ele;
13            this.defaults = {
14                limit:'',
15                top:0,
16                break:0,
17                type:1, //TYPE = 1 : FIXT ON TOP | TYPE = 2 : FIX ON BOTTOM
18                zindex:100,
19            };
20            this.options = $.extend({},this.defaults,opt);
21            this.init();
22            this.run();
23        }
24    }
25    mnfixed.prototype.init = function(){
26        var _ = this;
27        // WRAP ELEMENT TO CLASS
28        _.ele.wrap("<div class='mnfixed_self'></div>");
29        _.ele.parents(".mnfixed_self").wrap("<div class='mnfixed_wrap'></div>");
30        // SET VAR
31        _.self  = _.ele.parents(".mnfixed_self");
32        _.wrap  = _.ele.parents(".mnfixed_wrap");
33        _.limit = $(_.options.limit);
34        // SETUP WIDTH AND POSITION
35        _.wrap.css({
36            "position":"relative",
37        });
38        _.self.css({
39            "z-index":_.options.zindex,
40        });
41        _.setElementHeight();
42        _.setElementWidth();
43    }
44    mnfixed.prototype.run = function(){
45        var _ = this;
46        $(window).on("load resize scroll",function(){
47            if(_.getBreak()==true){
48                // _.setElementHeight();
49                _.setElementWidth();
50                _.setElementLeft();
51                switch (_.options.type){
52                    case 1 :
53                        _.run_type_1();
54                        break;
55                    case 2 : 
56                        _.run_type_2();
57                        break;
58                }
59            }
60            else{
61                _.setElementDefault();
62            }
63        });
64    }
65    mnfixed.prototype.run_type_1 = function(){
66        var _ = this;
67        if($(window).scrollTop() > _.getElementOffset().top && _.getBreak()==true){
68            _.ele.removeClass("fixed_bottom");
69            _.ele.addClass("fixed");
70            _.self.css({
71                "position":"fixed",
72                "left":_.getElementOffset().left+"px",
73                "top":_.options.top+"px",
74            });
75        }
76        else{
77            _.ele.removeClass("fixed");
78            _.self.css({
79                "position":"initial",
80                "left":"0px",
81                "top":"0px",
82            });
83        }
84        if(typeof _.limit.offset() == "object" && _.getBreak()==true){
85            if(_.getElementOffset().bottom_scroll >= _.getLimitOffset().bottom){
86                var term_top = _.getLimitOffset().bottom - (_.getElementOffset().top + _.getElementHeight() + _.options.top);
87                _.ele.removeClass("fixed");
88                _.ele.addClass("fixed_bottom");
89                _.self.css({
90                    "position":"absolute",
91                    "left":"0px",
92                    "top":term_top+"px",
93                });
94            }
95        }
96    }
97    mnfixed.prototype.run_type_2 = function(){
98        var _ = this;
99        if(($(window).scrollTop() + $(window).outerHeight()) > _.getElementOffset().bottom && _.getBreak()==true){
100            _.ele.removeClass("fixed_bottom");
101            _.ele.addClass("fixed");
102            _.self.css({
103                "position":"fixed",
104                "left":_.getElementOffset().left+"px",
105                "top":"initial",
106                "bottom":"0px",
107            });
108        }
109        else{
110            _.ele.removeClass("fixed");
111            _.self.css({
112                "position":"initial",
113                "left":"0px",
114                "bottom":"0px",
115            });
116        }
117        if(typeof _.limit.offset() == "object" && _.getBreak()==true){
118            if(($(window).scrollTop() + $(window).outerHeight()) > _.getLimitOffset().bottom){
119                var term_top = _.getLimitOffset().bottom - (_.getElementOffset().top + _.getElementHeight());
120                _.ele.removeClass("fixed");
121                _.ele.addClass("fixed_bottom");
122                _.self.css({
123                    "position":"absolute",
124                    "left":"0px",
125                    "top":"initial",
126                    "bottom":-term_top+"px",
127                });
128            }
129        }
130    }
131    // GET VALUE
132    mnfixed.prototype.getLimitOffset = function(){
133        var _ = this;
134        if(typeof _.limit.offset() == "object"){
135            var ret = {};
136            ret.top           = _.limit.offset().top;
137            ret.bottom        = _.limit.offset().top + _.limit.outerHeight();
138            ret.left          = _.limit.offset().left;
139            ret.right         = _.limit.offset().right;
140            return ret;
141        }
142        else{
143            return false;
144        }
145    }
146    mnfixed.prototype.getElementOffset = function(){
147        var _ = this;
148        var ret = {};
149        if(_.options.type==1){
150            ret.top           = _.wrap.offset().top - _.options.top;
151            ret.bottom        = _.wrap.offset().top + _.wrap.outerHeight() + _.options.top;
152            ret.left          = _.wrap.offset().left;
153            ret.right         = _.wrap.offset().right;
154            ret.top_scroll    = $(window).scrollTop() + _.options.top;
155            ret.bottom_scroll = $(window).scrollTop() + _.ele.outerHeight() + _.options.top;
156            ret.left_scroll   = _.ele.offset().left;
157            ret.right_scroll  = _.ele.offset().right;
158        }
159        else if(_.options.type==2){
160            ret.top           = _.wrap.offset().top;
161            ret.bottom        = _.wrap.offset().top + _.wrap.outerHeight();
162            ret.left          = _.wrap.offset().left;
163            ret.right         = _.wrap.offset().right;
164            ret.top_scroll    = $(window).scrollTop();
165            ret.bottom_scroll = $(window).scrollTop() + _.ele.outerHeight();
166            ret.left_scroll   = _.ele.offset().left;
167            ret.right_scroll  = _.ele.offset().right;
168        }
169        return ret;
170    }
171    mnfixed.prototype.getElementHeight = function(){
172        var _ = this;
173        return _.ele.outerHeight();
174    }
175    mnfixed.prototype.getElementWidth = function(){
176        var _ = this;
177        return _.wrap.outerWidth();
178    }
179    mnfixed.prototype.getBreak = function(){
180        var _ = this;
181        if($(window).outerWidth()>=_.options.break){
182            return true;
183        }
184        else{
185            return false;
186        }
187    }
188    // SET VALUE
189    mnfixed.prototype.setElementWidth = function(){
190        var _ = this;
191        _.self.css({
192            "width":_.getElementWidth(),
193        });
194    }
195    mnfixed.prototype.setElementHeight = function(){
196        var _ = this;
197        _.wrap.css({
198            "position":"relative",
199            "height": _.getElementHeight(),
200        });
201    }
202    mnfixed.prototype.setElementLeft = function(){
203        var _ = this;
204        _.self.css({
205            "left":_.getElementOffset().left+"px",
206        });
207    }
208    mnfixed.prototype.setElementDefault = function(){
209        var _ = this;
210        _.ele.removeClass("fixed");
211        _.ele.removeClass("fixed_bottom");
212        _.wrap.css({
213            "position":"initial",
214            "height":"initial",
215        });
216        _.self.css({
217            "position":"initial",
218            "left":"initial",
219            "top":"initial",
220            "width":"initial",
221        });
222    }
223    // CALL PLUGIN
224    $.prototype.mnfixed = function(options) {
225        var _ = this;
226        if(typeof _.offset() == "object"){
227            var opt = arguments[0];
228            _ = new mnfixed(_, opt);
229        }
230        else{
231            console.log("No Excertion !!!!!, ["+_+"]");
232        }
233    }
234})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.