简体   繁体   English

Javascript代码未在Chrome上运行

[英]Javascript code not running on Chrome

I have created a simple image slider using Javascript and JQuery, the code is running fine in safari both locally and online however in Chrome it is not running. 我使用Javascript和JQuery创建了一个简单的图像滑块,代码在本地和在线的safari中运行良好,但在Chrome中它没有运行。 Chrome is also throwing up no errors in the console so I'm finding it difficult to pinpoint the exact issue. Chrome也没有在控制台中出现任何错误,因此我发现很难找到确切的问题。 I realise having read into the problem that I should perhaps have my scripts the other way round so the slider.js goes first then the Ajax one however when I do this the script and therefore images do not load in Safari or Chrome. 我意识到已经读过这个问题,我应该让我的脚本反过来,所以slider.js首先是Ajax,但是当我这样做时,脚本因此无法在Safari或Chrome中加载图像。 Cheers. 干杯。

I have the following HTML code: 我有以下HTML代码:

<body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <div id="slider"></div>
  <script src="slider.js" type="text/javascript"></script>
</body>

And JS 和JS

slideShow();
var imgArray = [
    'Images/image1.jpg',
    'Images/image2.jpg',
    'Images/image3.jpg',
    'Images/image4.jpg',
    'Images/image5.jpg',
    'Images/image6.jpg',
    'Images/image7.jpg',
    'Images/image8.jpg'
  ],
curIndex = 0;
imgDuration = 5000;

function slideShow() {
$("#slider")
  .fadeOut('slow', function() {
      var img = $("<img />")
          .attr('src', imgArray[curIndex])
          .on('load', function() {
              $("#slider")
                  .html(img)
                  .fadeIn('normal', function() {
                      curIndex++;
                      if (curIndex == imgArray.length) {
                          curIndex = 0;
                      }
                      setTimeout(slideShow, imgDuration);
                  });
          });
  });
}

您可能还没有清除我认为的超时计时器。

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

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