织梦CMS图片太大自动按比例缩放

  1. 使用 JavaScript 脚本
    • 在页面中添加以下 JavaScript 脚本:
      <script type="text/javascript">
      function resizeImage(ImgD, iwidth, iheight) {
          var image = new Image();
          image.src = ImgD.src;
          if (image.width > 0 && image.height > 0) {
              if (image.width / image.height >= iwidth / iheight) {
                  if (image.width > iwidth) {
                      ImgD.width = iwidth;
                      ImgD.height = (image.height * iwidth) / image.width;
                  } else {
                      ImgD.width = image.width;
                      ImgD.height = image.height;
                  }
              } else {
                  if (image.height > iheight) {
                      ImgD.height = iheight;
                      ImgD.width = (image.width * iheight) / image.height;
                  } else {
                      ImgD.width = image.width;
                      ImgD.height = image.height;
                  }
              }
              ImgD.alt = image.width + "×" + image.height;
          }
      }
      </script>
    • 在图片标签中调用该函数:
      <img src="path/to/image.jpg" onload="resizeImage(this, 300, 200)" />

       

posted @   黄文Rex  阅读(3)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示