0

最近从 Django 切换到 Node.js 并且我的 svg html 没有正确加载,所有其他静态文件似乎都很好。

在这里你可以找到我的 html:

<svg class="svg-features-top" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="none">
   <path position="fixed" d="M55,0 L68,35 Q72,45 80,40 L100,30 100,0 Z" fill="#2b016d"/>
</svg>  

我正在尝试矢量化的 CSS 中的背景图像:

.section--intro{
    min-width:100%;
    height:100%;
    -webkit-background-size: 100%; 
    -moz-background-size: 100%;
    -o-background-size: 100%;
    background-size: 100%;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover; 
    background-size: cover;
    background-position:center bottom;
    background-image:url(images/bg.jpg);
    position:relative;
    overflow:hidden;
}

背景图像根本没有加载,我非常感谢我能得到的任何帮助

4

1 回答 1

1

可能,您没有使用 Node.js 正确地提供静态文件(在这种情况下为图像)。当您尝试获取图像时,例如:/images/bg.jpg,会发生以下情况:

  • 您的浏览器向服务器发出请求
  • 您的服务器(或 Web 应用程序)接受请求并且应该明确知道如何处理它。否则,它返回 404。

如果你使用 Express 作为你的 Node.js 框架,你可以告诉你的 Node.js 很容易地处理这样的请求:

const path = require('path');
app.use('/images', express.static(path.join(__dirname, 'images')))

此外,您可以在此处查看文档:https ://expressjs.com/en/starter/static-files.html

之后,您的 Node.js 应用程序应该能够为任何/images/请求返回图像内容。如果您为您的应用程序使用不同的框架,这不是问题,您只需要在文档中找到正确的提示,通过关键字搜索:static filesserve files

PS。SVG 图像内容不是 HTML,而是 XML

于 2018-08-17T11:44:34.877 回答