1const button = document.querySelectorAll('.button'); 2const arr = new Array(button.length).fill(false); 3 4button.forEach((item, index) => { 5 const tooltip = item.querySelector('.tooltip');//夿æ¯å¦åå¨äºçº§èå 6 if (tooltip) { 7 const popperInstance = Popper.createPopper(item, tooltip, { 8 modifiers: [ 9 { 10 name: 'offset', 11 options: { 12 offset: [0, 8], 13 }, 14 }, 15 { 16 name: 'preventOverflow', 17 options: { 18 padding:{right: 8}, 19 }, 20 }, 21 ], 22 }); 23 24 function show() { 25 arr[index] = true; 26 tooltip.classList.add('second-menu-model-show'); 27 // ä½¿å·¥å ·æç¤ºå¯è§ 28 tooltip.setAttribute('data-show', ''); 29 // å¯ç¨äºä»¶ä¾¦å¬å¨ 30 popperInstance.setOptions((options) => ({ 31 ...options, 32 modifiers: [ 33 ...options.modifiers, 34 { name: 'eventListeners', enabled: true, }, 35 ], 36 })); 37 38 // æ´æ°ä½ç½® 39 popperInstance.update(); 40 } 41 42 function debounce(func,wait,immediate) { 43 let timer; 44 45 return function () { 46 let context = this; 47 let args = arguments; 48 49 if (timer) clearTimeout(timer); 50 if (immediate) { 51 var callNow = !timer; 52 timer = setTimeout(() => { 53 timer = null; 54 }, wait) 55 if (callNow) func.apply(context, args) 56 } else { 57 timer = setTimeout(function(){ 58 func.apply(context, args) 59 }, wait); 60 } 61 } 62 } 63 64
65 function hide() { 66 // éèå·¥å ·æç¤º 67 if (arr[index]) { 68 return; 69 } 70 tooltip.removeAttribute('data-show'); 71 // ç¦ç¨äºä»¶ä¾¦å¬å¨ 72 popperInstance.setOptions((options) => ({ 73 ...options, 74 modifiers: [ 75 ...options.modifiers, 76 { name: 'eventListeners', enabled: false }, 77 ], 78 })); 79 } 80 81 const debounceHide = debounce(hide, 100) 82 83 const showEvents = ['mouseenter', 'focus']; 84 const hideEvents = ['mouseleave', 'blur']; 85 86 showEvents.forEach((event) => { 87 item.addEventListener(event, show); 88 }); 89 90 hideEvents.forEach((event) => { 91 item.addEventListener(event, () => { 92 arr[index] = false; 93 debounceHide(); 94 }); 95 }); 96 } 97 98})
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.