logo

今日海淘优惠:258条

Wesdut 37-in-1 Precision Screwdriver Set Bearing Steel $5.99
发布时间:2026-04-18 08:00:19
Amazon(US)
Wesdut 37-in-1 Precision Screwdriver Set Bearing Steel $5.99
去购买
Amazon(US)
//计算dom style if (typeof getComputedStyle == 'undefined') { if (document.body.currentStyle) { window.getComputedStyle = function(el) { return el.currentStyle; } } else { window.getComputedStyle = {}; } } /** * 设置lazy高度 * @param outerContainer lazy外层容器(用于计算宽度) * @param images 所有lazy图片 */ function setLazyHeight(outerContainer, images) { var maxWidth, containerStyle, orgSrc, orgRatio, orgWidth, width, imgStyle, imgWidth, actualHeight = 100; //外层容器 maxWidth = outerContainer.offsetWidth; containerStyle = getComputedStyle(outerContainer); maxWidth -= (parseFloat(containerStyle.paddingLeft) + parseFloat(containerStyle.paddingRight)); maxWidth = maxWidth || (window.innerWidth - 30); for (var i = 0, len = images.length; i < len; i++) { orgSrc = images[i].getAttribute('data-src'); orgRatio = images[i].getAttribute('data-ratio'); orgWidth = images[i].getAttribute('data-w') || images[i].getAttribute('data-width'); width = images[i].getAttribute('width'); // sp-in-deal 折扣插入晒货或文章 if (!orgSrc || !parseFloat(orgRatio) || !orgWidth || images[i].closest('.sp-in-deal')) { continue; } orgWidth = Math.min(orgWidth, maxWidth); if(width) { orgWidth = Math.min(orgWidth, width); } if (images[i].closest('.dm_table')) { var cell = images[i].closest('td') || images[i].closest('th'); var cellRect = cell.getBoundingClientRect(); orgWidth = Math.min(orgWidth, cellRect.width - 10); // 10: 左右padding之和 } if (orgRatio && orgRatio > 0) { imgStyle = getComputedStyle(images[i]); imgWidth = images[i].style.width; //图片设置过真实宽度 if ( imgWidth && imgWidth != 'auto' ) { orgWidth = parseFloat(imgStyle.width); } actualHeight = orgWidth / orgRatio; var smallImgHeight = orgWidth > 280 ? (280 / orgRatio) : actualHeight; smallImgHeight = statistics.interfacedata.platform === "PC" ? smallImgHeight : maxWidth / orgRatio * 0.4; actualHeight = $(images[i]) .parents('.dm_insert_block') .hasClass('dm_insert_img_small') ? smallImgHeight : actualHeight; images[i].style.cssText += "aspect-ratio: " + orgRatio + ';'; } else { images[i].style.cssText += "visibility: hidden !important;"; } if (!images[i].closest('.dm_table')) { if (actualHeight < 61) { var bgSize = actualHeight * .8; images[i].style.cssText += 'background-size: auto ' + bgSize + 'px;'; } if (actualHeight < 165) { images[i].style.cssText += 'min-height:auto;'; } images[i].style.cssText += "height: " + actualHeight + "px !important;"; } } } var doc = document, outContainer = doc.querySelector('.edit-content'); if (doc.addEventListener) { doc.addEventListener('DOMContentLoaded', function() { if (outContainer) { setLazyHeight(outContainer, [].filter.call(doc.querySelectorAll('.edit-content img.lazyload'), item => !item.closest('.dm_table'))); } }); } else { doc.onreadystatechange = function() { if (doc.readyState === 'complete') { if (outContainer) { setLazyHeight(outContainer, [].filter.call(doc.querySelectorAll('.edit-content img.lazyload'), item => !item.closest('.dm_table'))); } } } }