Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 如何从所需的任何索引启动carousel中的onCycleTo方法?_Javascript_Html_Css_Carousel_Materialize - Fatal编程技术网

Javascript 如何从所需的任何索引启动carousel中的onCycleTo方法?

Javascript 如何从所需的任何索引启动carousel中的onCycleTo方法?,javascript,html,css,carousel,materialize,Javascript,Html,Css,Carousel,Materialize,最近在我的项目中,我遇到了一个问题,在carousel中使用onCycleTo方法 //carouselimage is the images in carousel for(var i=0;i<carouselimage.length;i++) { if(filename==carouselimage[i].name) {

最近在我的项目中,我遇到了一个问题,在carousel中使用onCycleTo方法

//carouselimage is the images in carousel
for(var i=0;i<carouselimage.length;i++)
                {
                        if(filename==carouselimage[i].name)
                        {
                                $('.carousel').carousel('set', i);
                                break;
                        }
                }


$('.carousel').carousel({
      onCycleTo: function (ele) {
      console.log(ele);
      console.log($(ele).index());  
      var carousellength=document.getElementsByTagName("img").length;
      var carouselitem=document.getElementsByTagName("img");
      for(var i=0;i<carousellength;i++)
      {
        if($(ele).index()==i)
        {
            var filen=carouselitem[i].name;
            filen+=".mp3";
            var storage=firebase.storage().ref(filen);
            storage.getDownloadURL().then(function(url){document.getElementById("playing-song").src=url;})
                                         .catch(function(error){M.toast({html:"Network issue",classes:'rounded'});});
        }
      }
    }
});
//carouselimage是carousel中的图像
对于(var i=0;i