优化图片加载时的显示

This commit is contained in:
2022-03-31 00:19:06 +08:00
parent 1a623785e2
commit 753781ad1a
2 changed files with 21 additions and 6 deletions

View File

@@ -65,6 +65,13 @@
margin: 0 auto; margin: 0 auto;
} }
.ext-img__warpper.loading {
min-height: 100px;
background: url('/static/loading.gif') center no-repeat;
background-size: 25px 25px;
display: block;
}
.left-container .img-link img { .left-container .img-link img {
max-height: 500px; max-height: 500px;
} }

View File

@@ -77,6 +77,10 @@ function normalize_url(url) {
return /^https?:\/\//.test(url) ? url : 'http://' + url; return /^https?:\/\//.test(url) ? url : 'http://' + url;
} }
function stop_loading(e) {
e.target.parentNode.classList.remove('loading');
}
// props: text, show_pid, color_picker, search_param // props: text, show_pid, color_picker, search_param
export class HighlightedMarkdown extends Component { export class HighlightedMarkdown extends Component {
render() { render() {
@@ -96,12 +100,16 @@ export class HighlightedMarkdown extends Component {
shouldProcessNode: (node) => node.name === 'img', shouldProcessNode: (node) => node.name === 'img',
processNode(node, index) { processNode(node, index) {
return ( return (
<span className="ext-img__warpper loading">
<img <img
src={normalize_url(node.attribs.src)} src={normalize_url(node.attribs.src)}
alt={node.alt} alt={node.alt}
className="ext-img" className="ext-img"
referrerPolicy="no-referrer" referrerPolicy="no-referrer"
onError={stop_loading}
onLoad={stop_loading}
/> />
</span>
); );
}, },
}, },