有效的HTML代码:

<a class="fancybox-gallery" href="http://sale.coupsoft.com/uploads/938218/logo.png">
    <img class="animate scale animated" src="http://sale.coupsoft.com/uploads/938218/logo.png" alt="Image1">
    <div class="image-hover">
        <i class="icon-zoom-in-2"></i>
    </div>
</a>


失败的HTML代码:

<a class="fancybox-gallery" href="http://wallpapercraze.com/images/wallpapers/nowallpaper-585747.jpeg">
    <img class="animate scale animated" src="http://wallpapercraze.com/images/wallpapers/nowallpaper-585747.jpeg" alt="Image1" style="height:75px">
    <div class="image-hover">
        <i class="icon-zoom-in-2"></i>
    </div>
</a>


当我尝试从我的网站加载图像时,它无法成功执行,但是当我尝试从外部URL加载图像时,fancybox将重定向到该URL。我该如何解决这个问题,为什么会发生呢?

最佳答案

在这两种情况下,请检查我的工作代码。

还有一个JSFIDDLE



$("a.fancybox-gallery").fancybox({
  'transitionIn': 'elastic',
  'transitionOut': 'elastic',
  'speedIn': 600,
  'speedOut': 200,
  'overlayShow': false
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js"></script>
<link rel='stylesheet' href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" />

<a class="fancybox-gallery" href="http://sale.coupsoft.com/uploads/938218/logo.png">
  <img class="animate scale animated" src="http://sale.coupsoft.com/uploads/938218/logo.png" alt="Image1">
  <div class="image-hover">
    <i class="icon-zoom-in-2"></i>
  </div>
</a>

<a class="fancybox-gallery" href="http://wallpapercraze.com/images/wallpapers/nowallpaper-585747.jpeg">
  <img class="animate scale animated" src="http://wallpapercraze.com/images/wallpapers/nowallpaper-585747.jpeg" alt="Image1" style="height:75px">
  <div class="image-hover">
    <i class="icon-zoom-in-2"></i>
  </div>
</a>

关于javascript - Fancybox无法从外部URL加载图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40464310/

10-09 18:11