关于模块模板图片尺寸适配问题,建议通过以下三种技术方案解决:
一、模板层CSS强制适配方案
在模块模板的对应样式表中增加以下CSS代码:
- .thread-image-box {
- width: 390px !important;
- height: 260px; /* 根据实际比例调整 */
- overflow: hidden;
- position: relative;
- }
- .thread-image-box img {
- width: 100% !important;
- height: 100% !important;
- object-fit: cover;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- }
复制代码
二、模板层动态渲染方案
修改模块模板文件(如forum_thread.htm)的图片输出部分:
- <!--{loop $threadlist $key $thread}-->
- <div class="image-container">
- <!--{if $thread[image]}-->
- <img src="$thread[image]"
- style="width:390px;height:auto;transform: scale(1.05);transition: all 0.3s ease"
- onload="this.style.opacity=1"
- class="lazyload"
- data-original="{getimgurl($thread[image], 390)}">
- <!--{/if}-->
- </div>
- <!--{/loop}-->
复制代码
三、数据源层适配方案(需二次开发)
1. 修改模块的source/class/block/forum/block_thread.php文件
- // 找到图片处理部分修改为:
- if($post['first'][$this->setting['picrequired']]) {
- $thread['image'] = getimgurl($post['first'][$this->setting['picrequired']], 390, 260); // 强制指定尺寸
- $thread['image'] = preg_replace('/width=\d+/', 'width=390', $thread['image']);
- $thread['image'] = preg_replace('/height=\d+/', 'height=260', $thread['image']);
- }
复制代码
四、混合解决方案推荐:
1. 后台设置缩略图尺寸为390x260
2. 在extend_module/style.css追加:
- .module-wrap .c-img-box {
- aspect-ratio: 390/260;
- display: flex;
- justify-content: center;
- background: #f5f5f5;
- }
- .module-wrap img {
- max-width: 100%!important;
- height: auto!important;
- object-position: center center;
- }
复制代码
注意事项:
1. 当原图宽高比与目标尺寸不符时,建议使用CSS的object-fit: cover属性保持比例
2. 对移动端适配需追加媒体查询:
- @media (max-width:768px){
- .module-wrap img {
- max-width: 100vw!important;
- }
- }
复制代码
如需更深入的功能定制,可访问DZ插件网获取专业的技术支持方案。实际开发中建议同时处理WEBP格式转换和懒加载优化,以提升页面加载性能。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。 |