Background Image not grabbing from Google Drive file.

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

Background Image not grabbing from Google Drive file

问题

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

这是我现在的代码。

  1. body,
  2. html {
  3. height: 100%;
  4. }
  5. .parallax {
  6. /* image I want parallax on */
  7. background-image: url('G:\My Drive\Website\Parallax\TriangleHR.png');
  8. /* Full height */
  9. height: 100%;
  10. /* Create scrolling effect */
  11. background-attachment: fixed;
  12. background-position: center;
  13. background-repeat: no-repeat;
  14. background-size: cover;
  15. }
  16. /* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
  17. @media only screen and (max-device-width: 1366px) {
  18. .parallax {
  19. background-attachment: scroll;
  20. }
  21. }
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <link rel="stylesheet" href="G:\My Drive\Website\Parallax\styles.css">
  6. </head>
  7. <body>
  8. <div class="parallax"></div>
  9. <div style="height:1000px;background-color:red;font-size:36px">
  10. <p>Allows for scrolling.</p>
  11. </div>
  12. <div class="parallax"></div>
  13. </body>
  14. </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 -->

  1. body,
  2. html {
  3. height: 100%;
  4. }
  5. .parallax {
  6. /* image I want parallax on */
  7. background-image: url(&#39;G:\My Drive\Website\Parallax\TriangleHR.png&#39;);
  8. /* Full height */
  9. height: 100%;
  10. /* Create scrolling effect */
  11. background-attachment: fixed;
  12. background-position: center;
  13. background-repeat: no-repeat;
  14. background-size: cover;
  15. }
  16. /* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
  17. @media only screen and (max-device-width: 1366px) {
  18. .parallax {
  19. background-attachment: scroll;
  20. }
  21. }

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

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html&gt;
  3. &lt;head&gt;
  4. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  5. &lt;link rel=&quot;stylesheet&quot; href=&quot;G:\My Drive\Website\Parallax\styles.css&quot;&gt;
  6. &lt;/head&gt;
  7. &lt;body&gt;
  8. &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;
  9. &lt;div style=&quot;height:1000px;background-color:red;font-size:36px&quot;&gt;
  10. &lt;p&gt;Allows for scrolling.&lt;/p&gt;
  11. &lt;/div&gt;
  12. &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;
  13. &lt;/body&gt;
  14. &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:///",如这里所提到的。

你可以尝试这样做:

  1. <!-- begin snippet: js hide: false console: true babel: false -->
  2. <!-- language: lang-css -->
  3. body,
  4. html {
  5. height: 100%;
  6. }
  7. .parallax {
  8. /* image I want parallax on */
  9. background-image: url('file:///G:\My Drive\Website\Parallax\TriangleHR.png');
  10. /* Full height */
  11. height: 100%;
  12. /* Create scrolling effect */
  13. background-attachment: fixed;
  14. background-position: center;
  15. background-repeat: no-repeat;
  16. background-size: cover;
  17. }
  18. /* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
  19. @media only screen and (max-device-width: 1366px) {
  20. .parallax {
  21. background-attachment: scroll;
  22. }
  23. }
  24. <!-- language: lang-html -->
  25. <!DOCTYPE html>
  26. <html>
  27. <head>
  28. <meta name="viewport" content="width=device-width, initial-scale=1">
  29. <link rel="stylesheet" href="file:///G:\My Drive\Website\Parallax\styles.css">
  30. </head>
  31. <body>
  32. <div class="parallax"></div>
  33. <div style="height:1000px;background-color:red;font-size:36px">
  34. <p>Allows for scrolling.</p>
  35. </div>
  36. <div class="parallax"></div>
  37. </body>
  38. </html>
  39. <!-- 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 -->

  1. body,
  2. html {
  3. height: 100%;
  4. }
  5. .parallax {
  6. /* image I want parallax on */
  7. background-image: url(&#39;file:///G:\My Drive\Website\Parallax\TriangleHR.png&#39;);
  8. /* Full height */
  9. height: 100%;
  10. /* Create scrolling effect */
  11. background-attachment: fixed;
  12. background-position: center;
  13. background-repeat: no-repeat;
  14. background-size: cover;
  15. }
  16. /* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
  17. @media only screen and (max-device-width: 1366px) {
  18. .parallax {
  19. background-attachment: scroll;
  20. }
  21. }

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

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html&gt;
  3. &lt;head&gt;
  4. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  5. &lt;link rel=&quot;stylesheet&quot; href=&quot;file:///G:\My Drive\Website\Parallax\styles.css&quot;&gt;
  6. &lt;/head&gt;
  7. &lt;body&gt;
  8. &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;
  9. &lt;div style=&quot;height:1000px;background-color:red;font-size:36px&quot;&gt;
  10. &lt;p&gt;Allows for scrolling.&lt;/p&gt;
  11. &lt;/div&gt;
  12. &lt;div class=&quot;parallax&quot;&gt;&lt;/div&gt;
  13. &lt;/body&gt;
  14. &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:

确定