Background Image not grabbing from Google Drive file.

huangapple go评论53阅读模式
英文:

Background Image not grabbing from Google Drive file

问题

我正在开发一个需要视差效果的网站,但目前我是通过谷歌云盘和Notepad++运行它。出于某种原因,当我尝试使用 background-image: url(''); 时,它无法从谷歌云盘文件目录中获取图片。

这是我现在的代码。

body,
html {
  height: 100%;
}

.parallax {
  /* image I want parallax on */
  background-image: url('G:\My Drive\Website\Parallax\TriangleHR.png');
  /* Full height */
  height: 100%;
  /* Create scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

/* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */

@media only screen and (max-device-width: 1366px) {
  .parallax {
    background-attachment: scroll;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="G:\My Drive\Website\Parallax\styles.css">
</head>

<body>
  <div class="parallax"></div>

  <div style="height:1000px;background-color:red;font-size:36px">
    <p>Allows for scrolling.</p>
  </div>

  <div class="parallax"></div>

</body>

</html>

这应该在所有电脑/笔记本电脑上启用视差效果,并在所有手机上禁用它,以减轻压力/延迟。然而它甚至都不显示图片。

英文:

I am working on a website that requires parallax, but I am currently running it out of Google Drive and Notepad++. For some reason, when I try to use background-image: url(&#39;&#39;);, It does not pull up the image from the Google Drive file directory.

Here is the code I have right now.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body,
html {
  height: 100%;
}

.parallax {
  /* image I want parallax on */
  background-image: url(&#39;G:\My Drive\Website\Parallax\TriangleHR.png&#39;);
  /* Full height */
  height: 100%;
  /* Create scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


/* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */

@media only screen and (max-device-width: 1366px) {
  .parallax {
    background-attachment: scroll;
  }
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;G:\My Drive\Website\Parallax\styles.css&quot;&gt;
&lt;/head&gt;

&lt;body&gt;


  &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;

  &lt;div style=&quot;height:1000px;background-color:red;font-size:36px&quot;&gt;
    &lt;p&gt;Allows for scrolling.&lt;/p&gt;
  &lt;/div&gt;

  &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

This should activate parallax for all computers/laptops and disable it for all phones for less stress/lag.
However it doesn't even show the image at all.

答案1

得分: 1

我认为你可能错过了 "file:///",如这里所提到的。

你可以尝试这样做:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->
body,
html {
  height: 100%;
}

.parallax {
  /* image I want parallax on */
  background-image: url('file:///G:\My Drive\Website\Parallax\TriangleHR.png');
  /* Full height */
  height: 100%;
  /* Create scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


/* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */

@media only screen and (max-device-width: 1366px) {
  .parallax {
    background-attachment: scroll;
  }
}

<!-- language: lang-html -->
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="file:///G:\My Drive\Website\Parallax\styles.css">
</head>

<body>


  <div class="parallax"></div>

  <div style="height:1000px;background-color:red;font-size:36px">
    <p>Allows for scrolling.</p>
  </div>

  <div class="parallax"></div>

</body>

</html>

<!-- end snippet -->
英文:

I think you might have missed "file:///"

as mentioned here

You can try doing:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body,
html {
  height: 100%;
}

.parallax {
  /* image I want parallax on */
  background-image: url(&#39;file:///G:\My Drive\Website\Parallax\TriangleHR.png&#39;);
  /* Full height */
  height: 100%;
  /* Create scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


/* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */

@media only screen and (max-device-width: 1366px) {
  .parallax {
    background-attachment: scroll;
  }
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;file:///G:\My Drive\Website\Parallax\styles.css&quot;&gt;
&lt;/head&gt;

&lt;body&gt;


  &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;

  &lt;div style=&quot;height:1000px;background-color:red;font-size:36px&quot;&gt;
    &lt;p&gt;Allows for scrolling.&lt;/p&gt;
  &lt;/div&gt;

  &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月10日 22:27:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定