fix: empty img

This commit is contained in:
hyper 2026-02-27 21:24:06 +08:00
parent 95be758bcc
commit 72e376a6ad
1 changed files with 10 additions and 9 deletions

View File

@ -32,15 +32,16 @@ customElement("md-bg", {}, (props, { element }) => {
const [image] = createResource(resolvedSrc, loadImage);
createEffect(() => {
// 图片加载完成后,将背景图片设置到 article 元素
console.log(resolvedSrc, image(), articleEl);
if (image() && articleEl) {
articleEl.style.backgroundImage = `url(${resolvedSrc})`;
articleEl.style.backgroundSize = 'cover';
articleEl.style.backgroundPosition = 'center';
articleEl.style.backgroundRepeat = 'no-repeat';
}
createEffect(() => {
// 图片加载完成后,将背景图片设置到 article 元素
if(!articleEl)return;
articleEl.style.backgroundImage = '';
if (image()) {
articleEl.style.backgroundImage = `url(${resolvedSrc})`;
articleEl.style.backgroundSize = 'cover';
articleEl.style.backgroundPosition = 'center';
articleEl.style.backgroundRepeat = 'no-repeat';
}
});
return null;