1/** 2 * BOXä¿¡æ¯æ¡å°é¨ä»¶ JavaScript 3 */ 4 5class GentiatechBoxInfo { 6 constructor($scope) { 7 // æ£æ¥jQueryæ¯å¦å¯ç¨ 8 if (typeof jQuery === 'undefined') { 9 console.error('BOXä¿¡æ¯æ¡: jQueryæªå®ä¹'); 10 return; 11 } 12 13 this.$ = jQuery; // é¦å 设置jQueryå¼ç¨ 14 this.$element = $scope; 15 this.init(); 16 } 17 18 init() { 19 // ç¡®ä¿jQueryå¼ç¨å·²è®¾ç½® 20 if (!this.$) { 21 console.error('BOXä¿¡æ¯æ¡: jQueryå¼ç¨æªè®¾ç½®'); 22 return; 23 } 24 25 this.bindEvents(); 26 this.initAnimations(); 27 this.handleResize(); 28 29 // å»¶è¿æ§è¡ï¼ç¡®ä¿DOMå®å ¨å è½½ 30 setTimeout(() => { 31 this.forcePositionStyles(); 32 }, 100); 33 } 34 35 bindEvents() { 36 const $ = this.$; // æ¬å°jQueryå¼ç¨ 37 38 // 徿 æ¬åææ 39 this.$element.find('.mygica-box-info-icon').on('mouseenter', function() { 40 $(this).addClass('hovered'); 41 }).on('mouseleave', function() { 42 $(this).removeClass('hovered'); 43 }); 44 45 // ä¿¡æ¯æ¡æ¬åææ 46 this.$element.find('.mygica-box-info-info-box').on('mouseenter', function() { 47 $(this).addClass('hovered'); 48 }).on('mouseleave', function() { 49 $(this).removeClass('hovered'); 50 }); 51 52 // ååºå¼å¤ç 53 $(window).on('resize', () => { 54 this.handleResize(); 55 }); 56 } 57 58 initAnimations() { 59 // æ£æ¥æ¯å¦å¨è§å£ä¸ 60 const observer = new IntersectionObserver((entries) => { 61 entries.forEach(entry => { 62 if (entry.isIntersecting) { 63 this.startAnimations(); 64 observer.unobserve(entry.target); 65 } 66 }); 67 }, { 68 threshold: 0.1 69 }); 70 71 const container = this.$element.find('.mygica-box-info-container')[0]; 72 if (container) { 73 observer.observe(container); 74 } 75 } 76 77 startAnimations() { 78 const $ = this.$; // æ¬å°jQueryå¼ç¨ 79 const $infoBoxes = this.$element.find('.mygica-box-info-info-box'); 80 const $icons = this.$element.find('.mygica-box-info-icon'); 81 82 // å»¶è¿æ¾ç¤ºä¿¡æ¯æ¡ 83 $infoBoxes.each(function(index) { 84 const $box = $(this); 85 setTimeout(() => { 86 $box.addClass('animate-in'); 87 }, index * 150); 88 }); 89 90 // å»¶è¿æ¾ç¤ºå¾æ 91 $icons.each(function(index) { 92 const $icon = $(this); 93 setTimeout(() => { 94 $icon.addClass('animate-in'); 95 }, index * 100 + 50); 96 }); 97 } 98 99 handleResize() { 100 // è°è¯ä¿¡æ¯ 101 if (!this.$) { 102 console.error('BOXä¿¡æ¯æ¡ handleResize: jQueryå¼ç¨æªè®¾ç½®'); 103 return; 104 } 105 106 const $ = this.$; // æ¬å°jQueryå¼ç¨ 107 108 // 忬¡æ£æ¥jQuery彿°æ¯å¦å¯ç¨ 109 if (typeof $ !== 'function') { 110 console.error('BOXä¿¡æ¯æ¡ handleResize: jQuery䏿¯å½æ°', typeof $); 111 return; 112 } 113 114 const windowWidth = $(window).width(); 115 const $container = this.$element.find('.mygica-box-info-container'); 116 const $stage = this.$element.find('.mygica-box-info-stage'); 117 118 if (windowWidth <= 768) { 119 $container.addClass('mobile-layout'); 120 // ç§»å¨ç«¯ä¸ç¼©æ¾ 121 if ($stage.length) { 122 $stage.css('transform', 'none'); 123 } 124 } else { 125 $container.removeClass('mobile-layout'); 126 // æ¡é¢ç«¯ï¼æå®¹å¨å°ºå¯¸çæ¯ç¼©æ¾èå°ï¼é¿å 两侧è£å 127 if ($stage.length) { 128 const containerW = $container.innerWidth(); 129 const containerH = $container.innerHeight(); 130 const designW = 1200; // ä¸CSSèå°å®½åº¦ä¸è´ 131 const designH = 800; // ä¸CSSèå°é«åº¦ä¸è´ 132 const scale = Math.min(containerW / designW, containerH / designH); 133 $stage.css({ 134 transform: 'scale(' + scale + ')' 135 }); 136 } 137 } 138 139 // éæ°è®¡ç®ä½ç½®ï¼å¦æéè¦ï¼ 140 this.recalculatePositions(); 141 } 142 143 recalculatePositions() { 144 const $ = this.$; // æ¬å°jQueryå¼ç¨ 145 // å¨æäºæ åµä¸éæ°è®¡ç®å ç´ ä½ç½® 146 const windowWidth = $(window).width(); 147 148 if (windowWidth > 768) { 149 // æ¡é¢å¸å±çä½ç½®è°æ´é»è¾
150 this.adjustDesktopPositions(); 151 } 152 153 // 强å¶éæ°åºç¨å®ä½æ ·å¼ 154 this.forcePositionStyles(); 155 } 156 157 forcePositionStyles() { 158 // 强å¶éæ°åºç¨å ³é®çå®ä½æ ·å¼ 159 const $container = this.$element.find('.mygica-box-info-container'); 160 const $icons = this.$element.find('.mygica-box-info-icon'); 161 const $infoBoxes = this.$element.find('.mygica-box-info-info-box'); 162 const $stage = this.$element.find('.mygica-box-info-stage'); 163 164 // ç¡®ä¿å®¹å¨æ ·å¼æ£ç¡® 165 $container.css({ 166 'position': 'relative', 167 'width': '100%', 168 'display': 'flex', 169 'align-items': 'center', 170 'justify-content': 'center' 171 }); 172 if ($stage.length === 0) { 173 // 卿尿°æ åµä¸è¥ç¼ºå¤±èå°å®¹å¨ä¸å½±åå ¶å®æ ·å¼ 174 } 175 176 // ç¡®ä¿å¾æ åä¿¡æ¯æ¡çç»å¯¹å®ä½ 177 $icons.css('position', 'absolute'); 178 $infoBoxes.css('position', 'absolute'); 179 } 180 181 adjustDesktopPositions() { 182 const $ = this.$; // æ¬å°jQueryå¼ç¨ 183 // æ ¹æ®å®¹å¨å¤§å°è°æ´å¾æ åä¿¡æ¯æ¡ä½ç½® 184 const $container = this.$element.find('.mygica-box-info-container'); 185 const containerWidth = $container.width(); 186 const containerHeight = $container.height(); 187 188 // 妿容å¨å°ºå¯¸åçååï¼å¯ä»¥å¨è¿éè¿è¡ä½ç½®å¾®è° 189 if (containerWidth < 1200) { 190 $container.addClass('compact-layout'); 191 } else { 192 $container.removeClass('compact-layout'); 193 } 194 } 195 196 // å ¬å ±æ¹æ³ï¼å·æ°å°é¨ä»¶ 197 refresh() { 198 this.handleResize(); 199 this.initAnimations(); 200 } 201 202 // å ¬å ±æ¹æ³ï¼éæ¯å°é¨ä»¶ 203 destroy() { 204 const $ = this.$; // æ¬å°jQueryå¼ç¨ 205 this.$element.find('.mygica-box-info-icon').off('mouseenter mouseleave'); 206 this.$element.find('.mygica-box-info-info-box').off('mouseenter mouseleave'); 207 $(window).off('resize'); 208 } 209} 210 211// ç¡®ä¿jQueryå¯ç¨åååå§å 212(function() { 213 'use strict'; 214 215 // çå¾ jQueryå è½½ç彿° 216 function waitForJQuery(callback) { 217 if (typeof jQuery !== 'undefined') { 218 callback(jQuery); 219 } else { 220 setTimeout(function() { 221 waitForJQuery(callback); 222 }, 50); 223 } 224 } 225 226 // çå¾ jQueryå è½½å®æ 227 waitForJQuery(function($) { 228 // Elementorå端åå§å 229 $(window).on('elementor/frontend/init', function() { 230 if (window.elementorFrontend && window.elementorFrontend.hooks) { 231 window.elementorFrontend.hooks.addAction('frontend/element_ready/mygica_box_info.default', function($scope) { 232 new GentiatechBoxInfo($scope); 233 }); 234 } 235 }); 236 237 // ç´æ¥åå§åï¼éElementorç¯å¢ï¼ 238 $(document).ready(function() { 239 $('.mygica-box-info-container').each(function() { 240 if (!$(this).closest('.elementor').length) { 241 new GentiatechBoxInfo($(this).parent()); 242 } 243 }); 244 }); 245 }); 246 247})();
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.