使用UEditor上传图片时,图片过大超出编辑框,手机没法自适应。折腾啊折腾,记录一下。
之前上传图片很大没怎么理会,手动调一下,最近发现在手机上查看没法自适应,很是烦,便想着改掉这个问题。
好像其他项目不记得是使用js还是min.js ,所幸两个都加了一下ueditor.all.js和ueditor.all.min.js
//设置图片最大宽度,以免撑出滚动条
'img{max-width:100%;}'+
手机自适应相应页面增加样式即可
<style>
/*解决UEditor上传图片问题*/
img {
max-width: 100%; /*图片自适应宽度*/
height: auto;
}
</style>
只能编辑页面适应大小,但是手机无法自适应。
loader.setAttribute('style','max-width:650px');//设置上传图片最大宽度
$str = preg_replace('/(<img).+(src=\"?.+)images\/(.+\.(jpg|gif|bmp|bnp|png)\"?).+>/i',"\${1} \${2}uc/images/\${3}>",$str);
return str_replace('<img','<img width="100%" height="auto"',$str);