1. 程式人生 > >ueditor 上傳的圖片在內容裏顯示的尺寸過大的問題

ueditor 上傳的圖片在內容裏顯示的尺寸過大的問題

lba sim 寬度 ear move timeout ini css AD

技術分享圖片

沒改動之前是上面這樣的,圖片顯示不開,撐出了滾動條,想讓他自適應100%,不出現滾動條

網上有方法

1.ueditor 的 themes 文件夾下有個iframe.css 加入以下代碼,保存(原先的css文件應該是空的,只有一行註釋)/// 個人感覺沒用,調試了一下確實沒用不知為什麽,放在這了

技術分享圖片
img {  
 max-width: 100%; /*圖片自適應寬度*/  
}  
body {  
 overflow-y: scroll !important;  
}  
.view {  
 word-break: break-all;  
}  
.vote_area {  
 display: block;  
}  
.vote_iframe {  
 background-color: transparent;  
 border: 0 none;  
 height: 100%;  
}  
#edui1_imagescale{display:none !important;} 
技術分享圖片

前臺引入css

技術分享圖片
<script type="text/javascript">
  var ue = UE.getEditor(‘container‘, {
    toolbars: [
      [‘fullscreen‘,‘source‘,‘undo‘,‘redo‘,‘indent‘,‘bold‘,‘italic‘,‘underline‘,‘fontborder‘,‘snapscreen‘,‘print‘,‘preview‘,‘link‘,‘unlink‘,‘insertrow‘,‘insertcol‘,‘mergeright‘,‘mergedown‘,‘deleterow‘,‘deletecol‘,‘splittorows‘,‘splittocols‘,‘splittocells‘,‘fontfamily‘,‘fontsize‘,‘simpleupload‘,‘insertimage‘,‘spechars‘,‘searchreplace‘,‘justifyleft‘,‘justifyright‘,‘justifycenter‘],
      [‘justifyjustify‘,‘forecolor‘,‘backcolor‘,‘attachment‘,‘imagecenter‘,‘wordimage‘,‘inserttable‘,‘strikethrough‘, ‘superscript‘, ‘subscript‘, ‘removeformat‘, ‘formatmatch‘, ‘autotypeset‘, ‘blockquote‘, ‘pasteplain‘, ‘|‘, ‘forecolor‘, ‘backcolor‘, ‘insertorderedlist‘, ‘insertunorderedlist‘, ‘selectall‘, ‘cleardoc‘]
    ],
    iframeCssUrl: 
‘__PUBLIC__/other/ueditor/themes/iframe.css‘,// 引入css autoHeightEnabled: true, autoFloatEnabled: true }); </script>
技術分享圖片

2.ueditor.all.js 找到render:function(container){}修改如下:、// 親測好用

技術分享圖片
var html = ( ie && browser.version < 9  ? ‘‘ : ‘<!DOCTYPE html>‘) +
                    ‘<html xmlns=\‘http://www.w3.org/1999/xhtml\‘ class=\‘view\‘ ><head>‘ +
                    ‘<style type=\‘text/css\‘>‘ +
                    //設置四周的留邊
                    ‘.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n‘ +
                    //設置默認字體和字號
                    //font-family不能呢隨便改,在safari下fillchar會有解析問題
                    ‘body{margin:8px;font-family:sans-serif;font-size:16px;}‘ +
                    //設置圖片最大寬度,以免撐出滾動條
                ‘img
{max-width:100%;}‘+ //設置段落間距 ‘p{margin:5px 0;}</style>‘ + ( options.iframeCssUrl ? ‘<link rel=\‘stylesheet\‘ type=\‘text/css\‘ href=\‘‘ + utils.unhtml(options.iframeCssUrl) + ‘\‘/>‘ : ‘‘ ) + (options.initialStyle ? ‘<style>‘ + options.initialStyle + ‘</style>‘ : ‘‘) + ‘</head><body class=\‘view\‘ ></body>‘ + ‘<script type=\‘text/javascript\‘ ‘ + (ie ? ‘defer=\‘defer\‘‘ : ‘‘ ) +‘ id=\‘_initialScript\‘>‘ + ‘setTimeout(function(){editor = window.parent.UE.instants[\‘ueditorInstant‘ + me.uid + ‘\‘];editor._setup(document);},0);‘ + ‘var _tmpScript = document.getElementById(\‘_initialScript\‘);_tmpScript.parentNode.removeChild(_tmpScript);</script></html>‘;
技術分享圖片

其實就加了一句

經實驗,還是第二種好用

ueditor 上傳的圖片在內容裏顯示的尺寸過大的問題