Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击图像周围的空白区域时,Javascript幻灯片显示会出现问题_Javascript_Html_Css_Function_Slideshow - Fatal编程技术网

单击图像周围的空白区域时,Javascript幻灯片显示会出现问题

单击图像周围的空白区域时,Javascript幻灯片显示会出现问题,javascript,html,css,function,slideshow,Javascript,Html,Css,Function,Slideshow,所以我得到了这个幻灯片代码,当你点击一个图像时,它会消失在另一个图像中。但是,如果,例如,有一个垂直方向的图像,其右侧有空白,如果单击该空间,整个幻灯片显示就会出现小故障 这是我的网站,您可以在这里进行测试: 代码: $(document).ready(function() { $.fn.nextOrFirst = function (selector) { var next = this.next(selector); return (next.length) ? next

所以我得到了这个幻灯片代码,当你点击一个图像时,它会消失在另一个图像中。但是,如果,例如,有一个垂直方向的图像,其右侧有空白,如果单击该空间,整个幻灯片显示就会出现小故障

这是我的网站,您可以在这里进行测试:

代码:

$(document).ready(function() {
$.fn.nextOrFirst = function (selector) {
    var next = this.next(selector);
    return (next.length) ? next : this.prevAll(selector).last();
};
$("#cf2 img").click(function() {
    $(this)
    .removeClass('visible')
    .nextOrFirst()
    .addClass('visible');
  });
});
#cf2 {
  position:relative;
  height:281px;
  width:450px;
  margin:0 auto;
}
#cf2 img {
  position:absolute;
  left:0;
  max-height: 600px;
  max-width: 600px;
  opacity: 0;
  z-index: 0;
  -webkit-transition: opacity 1s ease-in-out;
  -moz-transition: opacity 1s ease-in-out;
  -o-transition: opacity 1s ease-in-out;
  transition: opacity 1s ease-in-out;
}

#cf2 img.visible {
  opacity: 1;
  z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cf2" class="shadow">
  <img class="visible" src="http://static.ddmcdn.com/gif/storymaker-best-hubble-space-telescope-images-20092-514x268.jpg" alt="1"/>
  <img src="http://economictimes.indiatimes.com/thumb/msid-45891755,width-640,resizemode-4/nasas-images-of-most-remarkable-events-you-cant-miss.jpg" alt="2"/>
  <img src="http://i.dailymail.co.uk/i/pix/2013/11/03/article-2486855-192ACC5200000578-958_964x682.jpg" alt="3"/>
  <img src="http://mstatic.mit.edu/nom150/items/199-HybridImage.jpg" alt="4"/>
</div>
CSS:

$(document).ready(function() {
$.fn.nextOrFirst = function (selector) {
    var next = this.next(selector);
    return (next.length) ? next : this.prevAll(selector).last();
};
$("#cf2 img").click(function() {
    $(this)
    .removeClass('visible')
    .nextOrFirst()
    .addClass('visible');
  });
});
#cf2 {
  position:relative;
  height:281px;
  width:450px;
  margin:0 auto;
}
#cf2 img {
  position:absolute;
  left:0;
  max-height: 600px;
  max-width: 600px;
  opacity: 0;
  z-index: 0;
  -webkit-transition: opacity 1s ease-in-out;
  -moz-transition: opacity 1s ease-in-out;
  -o-transition: opacity 1s ease-in-out;
  transition: opacity 1s ease-in-out;
}

#cf2 img.visible {
  opacity: 1;
  z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cf2" class="shadow">
  <img class="visible" src="http://static.ddmcdn.com/gif/storymaker-best-hubble-space-telescope-images-20092-514x268.jpg" alt="1"/>
  <img src="http://economictimes.indiatimes.com/thumb/msid-45891755,width-640,resizemode-4/nasas-images-of-most-remarkable-events-you-cant-miss.jpg" alt="2"/>
  <img src="http://i.dailymail.co.uk/i/pix/2013/11/03/article-2486855-192ACC5200000578-958_964x682.jpg" alt="3"/>
  <img src="http://mstatic.mit.edu/nom150/items/199-HybridImage.jpg" alt="4"/>
</div>
HTML:

$(document).ready(function() {
$.fn.nextOrFirst = function (selector) {
    var next = this.next(selector);
    return (next.length) ? next : this.prevAll(selector).last();
};
$("#cf2 img").click(function() {
    $(this)
    .removeClass('visible')
    .nextOrFirst()
    .addClass('visible');
  });
});
#cf2 {
  position:relative;
  height:281px;
  width:450px;
  margin:0 auto;
}
#cf2 img {
  position:absolute;
  left:0;
  max-height: 600px;
  max-width: 600px;
  opacity: 0;
  z-index: 0;
  -webkit-transition: opacity 1s ease-in-out;
  -moz-transition: opacity 1s ease-in-out;
  -o-transition: opacity 1s ease-in-out;
  transition: opacity 1s ease-in-out;
}

#cf2 img.visible {
  opacity: 1;
  z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cf2" class="shadow">
  <img class="visible" src="http://static.ddmcdn.com/gif/storymaker-best-hubble-space-telescope-images-20092-514x268.jpg" alt="1"/>
  <img src="http://economictimes.indiatimes.com/thumb/msid-45891755,width-640,resizemode-4/nasas-images-of-most-remarkable-events-you-cant-miss.jpg" alt="2"/>
  <img src="http://i.dailymail.co.uk/i/pix/2013/11/03/article-2486855-192ACC5200000578-958_964x682.jpg" alt="3"/>
  <img src="http://mstatic.mit.edu/nom150/items/199-HybridImage.jpg" alt="4"/>
</div>

如果我理解的话,这里的问题是当您在图像外部但在上一张图像的正方形内部单击时,幻灯片不会改变

这种方法不改变YoutJavaScript,而是改变html和一些选择器

在下面的示例中,我将每个


试图找到故障,但什么也找不到。你能更具体地说明这个小故障是如何发生的吗?页面冻结了?选择突出显示棒?一群蝗虫入侵你的家?(这在我身上时有发生)我明白了。但是非常感谢你的帮助!啊!!这很有道理。非常感谢,工作做得很好。:)显然,Java还是新手!