Jquery 在多个图像之间循环
我有这个问题:我想更改连续循环中Jquery 在多个图像之间循环,jquery,html,Jquery,Html,我有这个问题:我想更改连续循环中img元素的src属性 以下是我的HTML和jQuery代码: <img id="changeSlider" src="{{asset('uploads/photos/')}}{{photo.path}}" alt=""> <script type="text/javascript"> $(document).ready(function() { var i = 1; while(i < 10) { $
img
元素的src
属性
以下是我的HTML和jQuery代码:
<img id="changeSlider" src="{{asset('uploads/photos/')}}{{photo.path}}" alt="">
<script type="text/javascript">
$(document).ready(function() {
var i = 1;
while(i < 10) {
$("#changeSlider").attr('src', '{{asset("uploads/photos/")}}{{photos[0].path}}').delay(3000);
i++;
}
});
</script>
$(文档).ready(函数(){
var i=1;
而(i<10){
$(“#changeSlider”).attr('src','{asset(“uploads/photos/”)}{{{photos[0].path}}}').delay(3000);
i++;
}
});
您可以通过setIntervall定期更新图像路径,并循环浏览图像(假设有一个函数可以根据索引生成图像url):
什么是永远?你是说你想在一组图像之间重复循环?什么是
photos
变量?是的,我的意思是重复。。。photos是包含5-25个实体photo对象的数组,photo.path是Photography的路径不能有while循环。您需要使用setTimeout或onload。另外,您的JavaScript不会试图更改任何内容,下面是一个示例
var count = 20; // actual number of available photos
var next = 0;
window.setInterval(showNextImage, 3000);
function showNextImage() {
$('#changeSlider').prop('src', URL_OF_PHOTO(next));
next = (++next)%count;
}