简体   繁体   English

图像未显示在github页面上

[英]Images aren't displaying on github pages

I'm using github pages to host a practice website. 我正在使用github页面托管练习网站。 I've built a simple JS slideshow and the images in the slideshow are not displaying. 我建立了一个简单的JS幻灯片,幻灯片中的图像没有显示。 When I use Atom live server to display the site, the images and slideshow work fine. 当我使用Atom实时服务器显示站点时,图像和幻灯片可以正常工作。 When using github pages I inspected the active slideshow and it is moving through the image array fine as I can see the src attribute changing the way it should so I know the code is looping through the array properly. 当使用github页面时,我检查了活动的幻灯片,它正在图像数组中移动,因为我可以看到src属性更改了应有的方式,因此我知道代码在整个数组中正确循环。 I'm not sure what is wrong. 我不知道怎么了。

the relevant JavaScript 相关的JavaScript

const image = [
  '../images/karakoy-1.jpg',
  '../images/karakoy-2.jpg',
  '../images/karakoy-3.jpg',
  '../images/karakoy-4.jpg',
  '../images/karakoy-5.jpg',
];
let i = 0;
const imageContainer = document.getElementsByClassName('slideshow-image');
const time = 3000;

function changeSlide() {
  imageContainer[0].src = image[i];
  if (i < image.length - 1) {
    i++;
  } else {
    i = 0;
  }

  setTimeout('changeSlide()', time);
}

changeSlide();

I've also checked all the spelling and capitilization on the filenames. 我还检查了文件名的所有拼写和大小写。 Everything checks out. 一切都检查了。 Like I said, when I use Atom live server everything works fine. 就像我说的那样,当我使用Atom实时服务器时,一切正常。

UPDATE https://jtc10.github.io/Arcadia-Restaurant/ 更新https://jtc10.github.io/Arcadia-Restaurant/

Here is a link to the page. 这是页面的链接。 Click the "reservations" link. 点击“预订”链接。 The slideshow is on that page. 幻灯片在该页面上。

It's most likely an issue resolving relative paths between your local and live servers. 解决本地服务器和实时服务器之间的相对路径很可能是一个问题。

The requests with the relative paths are all returning 404 Not Found: 具有相对路径的请求全部返回404 Not Found:

在此处输入图片说明

I prefer to use the full path from root instead. 我宁愿使用root的完整路径。 This takes the ambiguity out of the situation. 这消除了歧义。

const image = [
    '/images/karakoy-1.jpg',
    '/images/karakoy-2.jpg',
    '/images/karakoy-3.jpg',
    '/images/karakoy-4.jpg',
    '/images/karakoy-5.jpg',
];

它尝试加载不存在的https://jtc10.github.io/images/karakoy-2.jpg ,从图像路径中删除../

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM