注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 获取所有符合条件的图片
const images = document.querySelectorAll('img[src*="www.guohao.asia"]');
// 遍历图片并调整样式
images.forEach(img => {
// 获取图片的实际宽度
const naturalWidth = img.naturalWidth;
// 根据图片宽度设置样式
if (naturalWidth < 600) {
img.style.maxWidth = 'none'; // 移除最大宽度限制
img.style.width = 'auto'; // 使用图片的实际宽度
} else {
img.style.width = '80%'; // 宽度大于等于450px时,设置为父容器的80%
}
});