Tencent / Tencent/cherry-markdown
[建议]尽可能的利用css去计算?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 4.9k
- Forks
- 572
- Avg merge
- 17h 5m
- Merged PRs (30d)
- 14
Description
-
1.用hidden=!0 替代 style.display=none更有性价比。
-
2.编辑区和预览区放在一个容器里面,方面当竖屏可以竖排而不是只能横排溢出
-
3.很明显给主容器加
height:100%没什么用,不如增加几层DIV,flex垂直布局,让编辑预览区自动适应高度,这样无需要JS去设置min-height
CSS变量化建议
一些浮动定位数据用var(--cherry-toolbar-xxx)
添加一个唯一的随机id标记主容器,类似这样
function creatSheet(){
var style = document.querySelector('#cherry-css-var');
if(!style)){
style = document.head.appendChild(document.createElement('style'));
style.setAttribute('id','cherry-css-var');
}
return style.sheet;
}
var css_var = {};
var css_pos;
var css_id = '#cherry-'+Math.random().toString().slice(2);
function updateVar(obj,prefix){
let sheet = creatSheet();
prefix = prefix?'-'+prefix+'-':'-';
Object.entries(obj).forEach(entry=>{
css_var['--cherry'+prefix+entry[0]] = entry[1]?entry[1]:'';
});
Object.assign(css_var,obj);
if(css_pos===undefined){
css_pos = sheet.rules.length;
}
if(sheet.rules[css_pos])sheet.deleteRule(css_pos);
sheet.insertRule(css_id+'{'+ Object.entries(css_var).map(v=>v[0]+':'+v[1]).join(';')+'}',css_pos);
}
updateVar({top:'0px'},'toolbar');
这些理论上dom几乎无修改,而且css calc min max运算有时候比js好用,特别自适应方面。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the editor and preview container layout, toolbar positioning, and the JavaScript style and min-height updates described in the issue. Done should include the proposed CSS-based sizing and responsive vertical layout, with the dynamic style changes and CSS variables working without unnecessary DOM updates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, javascript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100