PageSourceSearch

https://www.oreamalia.it/wp-content/themes/betheme/js/parallax/translate3d.js?ver=21.0.2

js oreamalia.it collected 2026-10-01 14:59:33 UTC 4,648 bytes, 257 lines download raw bytes

1/**
2 * Parallax
3 *
4 * Translate3d
5 * 1.0 | Muffin Group
6 */
7
8var mfnSetup = {
9  translate: null
10};
11
12(function($) {
13
14  /* globals jQuery */
15
16  "use strict";
17
18  /**
19   * mfnSetup
20   */
21
22  // has3d
23
24  var has3d = function() {
25
26    if (!window.getComputedStyle) {
27      return false;
28    }
29
30    var el = document.createElement('div'),
31      has3d,
32      transforms = {
33        'webkitTransform': '-webkit-transform',
34        'OTransform': '-o-transform',
35        'msTransform': '-ms-transform',
36        'MozTransform': '-moz-transform',
37        'transform': 'transform'
38      };
39
40    document.body.insertBefore(el, null);
41
42    for (var t in transforms) {
43      if (el.style[t] !== undefined) {
44        el.style[t] = "translate3d(1px,1px,1px)";
45        has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
46      }
47    }
48
49    document.body.removeChild(el);
50
51    return (has3d !== undefined && has3d !== null && has3d.length > 0 && has3d !== "none");
52  };
53
54  // browserPrefix
55
56  var browserPrefix = function() {
57
58    var el = document.createElement('div'),
59      vendor = ["ms", "O", "Webkit", "Moz"],
60      i, prefix;
61
62    for (i in vendor) {
63      if (el.style[vendor[i] + "Transition"] !== undefined) {
64        prefix = vendor[i];
65        break;
66      }
67    }
68    return prefix;
69  };
70
71  // __construct
72
73  var __construct = function() {
74
75    if (has3d()) {
76
77      mfnSetup.translate = function(el, x, y) {
78        el.css('-' + browserPrefix() + '-transform', 'translate3d(' + x + ', ' + y + ', 0)');
79      };
80
81    } else {
82
83      mfnSetup.translate = function(el, x, y) {
84        el.css({
85          "left": x,
86          "top": y
87        });
88      };
89
90    }
91  };
92
93  __construct();
94
95})(jQuery);
96
97(function($) {
98
99  "use strict";
100
101  /**
102   * $.fn.mfnParallax
103   */
104
105  $.fn.mfnParallax = function() {
106
107    var el = $(this),
108      parent = el.parent(),
109      speed = 500,
110      element, parentPos, windowH;
111
112    // imageSize
113
114    var imageSize = function(img) {
115
116      var w, h, l, t; // width, height, left, top
117
118      var imageW = img.get(0).naturalWidth;
119      var imageH = img.get(0).naturalHeight;
120
121      var parentW = img.parent().outerWidth();
122      var parentH = img.parent().outerHeight();
123
124      var windowH = $(window).height();
125
126      // fix for small sections
127      if (windowH > parentH) {
128        parentH = windowH;
129      }
130
131      var diff = imageW / parentW;
132
133      if ((imageH / diff) < parentH) {
134
135        w = imageW / (imageH / parentH);
136        h = parentH;
137
138        if (w > imageW) {
139
140          w = imageW;
141          h = imageH;
142
143        }
144
145      } else {
146
147        w = parentW;
148        h = imageH / diff;
149
150      }
151
152      l = (parentW - w) / 2;
153      t = (parentH - h) / 2;
154
155      return [w, h, l, t];
156    };
157
158    // parallax
159
160    var parallax = function() {
161
162      var scrollTop = $(window).scrollTop(),
163        scrollDiff, ratio, translateTop;
164
165      if (parentPos !== undefined) {
166
167        if (scrollTop >= parentPos.min && scrollTop <= parentPos.max) {
168
169          scrollDiff = scrollTop - parentPos.min;
170          ratio = scrollDiff / parentPos.height;
171
172          translateTop = windowH + (ratio * speed) - scrollDiff - (speed * (windowH / parentPos.height));
173
174          mfnSetup.translate(el, element.left + "px", -Math.round(translateTop) + "px");
175        }
176
177      }
178    };
179
180    // init
181
182    var init = function() {
183
184      windowH = $(window).height();
185
186      var initElement = function() {
187
188        var size = imageSize(el);
189
190        el.removeAttr('style').css({
191          'width': size[0],
192          'height': size[1]
193        });
194
195        mfnSetup.translate(el, size[2] + "px", size[3] + "px");
196
197        return {
198          'width': size[0],
199          'height': size[1],
200          'left': size[2],
201          'top': size[3]
202        };
203      };
204
205      element = initElement();
206
207      var initParent = function() {
208
209        var min = parent.offset().top - $(window).height();
210        var max = parent.offset().top + $(parent).outerHeight();
211
212        return {
213          'min': min,
214          'max': max,
215          'height': max - min
216        };
217      };
218
219      parentPos = initParent();
220    };
221
222    // reload
223
224    var reload = function() {
225
226      setTimeout(function() {
227        init();
228        parallax();
229      }, 50);
230
231    };
232
233    // .bind()
234
235    $(window).bind('load resize', reload);
236    $(window).bind('scroll', parallax);
237
238  };
239
240  /**
241   * $(document).ready
242   * Specify a function to execute when the DOM is fully loaded.
243   */
244
245  $(document).ready(function() {
246
247    if ($(".mfn-parallax").length) {
248
249      $(".mfn-parallax").each(function() {
250        $(this).mfnParallax();
251      });
252
253    }
254
255  });
256
257})(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.