Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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 Onsen ui转盘属性自动播放不工作_Javascript_Html_Css_Onsen Ui - Fatal编程技术网

Javascript Onsen ui转盘属性自动播放不工作

Javascript Onsen ui转盘属性自动播放不工作,javascript,html,css,onsen-ui,Javascript,Html,Css,Onsen Ui,我在这里使用onsen UI我在我的移动web应用程序中使用carousel,但是这里出现了一些问题,我无法使用属性autoplay <ons-page> <ons-toolbar> <div class="left"> <ons-toolbar-button onclick="prev()"> <ons-icon icon="md-chevron-left"></ons-ico

我在这里使用onsen UI我在我的移动web应用程序中使用carousel,但是这里出现了一些问题,我无法使用属性autoplay

   <ons-page>
     <ons-toolbar>
     <div class="left">
     <ons-toolbar-button onclick="prev()">
        <ons-icon icon="md-chevron-left"></ons-icon>
      </ons-toolbar-button>
     </div>
     <div class="center">Carousel</div>
     <div class="right">
      <ons-toolbar-button onclick="next()">
        <ons-icon icon="md-chevron-right"></ons-icon>
      </ons-toolbar-button>
      </div>
      </ons-toolbar>

     <ons-carousel fullscreen auto-scroll id="carousel">
     <ons-carousel-item style="background-color: #085078;">
        <div style="text-align: center; font-size: 30px; margin-top: 
       20px; 
      color: #fff;">
        BLUE
      </div>
      </ons-carousel-item>
      <ons-carousel-item style="background-color: #373B44;">
      <div style="text-align: center; font-size: 30px; margin-top: 20px; 
      color: #fff;">
        DARK
      </div>
       </ons-carousel-item>
       <ons-carousel-item style="background-color: #D38312;">
      <div style="text-align: center; font-size: 30px; margin-top: 20px; 
         color: #fff;">
        ORANGE
        </div>
        </ons-carousel-item>
       < /ons-carousel>  
       </ons-page>

没有出现错误消息,但我的自动播放选项不起作用。

如果您说“自动播放”是指
自动滚动
选项,我想您误解了
自动滚动
选项的目标,并期望旋转木马将在没有任何用户操作的情况下使用
自动滚动
选项浏览其项目

从:

自动滚动:如果设置了此属性,则在释放时,旋转木马将自动滚动到最近的项目边框

看看它是如何工作的。使用
auto scroll
选项,当用户想要滑动到转盘中的下一个或上一个项目时,她不需要滑动到最后。部分刷卡就足够了,因为旋转木马将自动完成刷卡。删除
自动滚动
选项,按Run并尝试滑动旋转木马。您将看到,刷卡在您释放的位置停止

因此,
自动滚动
不是自动播放。但究竟如何实现自动播放呢?只需在
setInterval
函数中使用旋转木马方法(
next
first
getActiveIndex
)和属性(
itemCount

setInterval(function(){ 
  var carousel = document.getElementById('carousel');
  if (carousel.getActiveIndex() === carousel.itemCount-1)
     carousel.first();
  else
     carousel.next(); 
}, 1000);
var prev=function(){
var carousel=document.getElementById('carousel');
上一个转盘();
};
var next=函数(){
var carousel=document.getElementById('carousel');
carousel.next();
};
ons.ready(函数(){
var carousel=document.addEventListener('postchange',函数(事件){
console.log('更改为'+event.activeIndex)
});
});
setInterval(函数(){
var carousel=document.getElementById('carousel');
if(carousel.getActiveIndex()==carousel.itemCount-1)
carousel.first();
其他的
carousel.next();
}, 1000);

旋转木马
蓝色
黑暗的
橙色


如果您说“autoplay”是指
自动滚动
选项,我想您误解了
自动滚动
选项的目标,并期望旋转木马将在没有任何用户操作的情况下使用
自动滚动
选项浏览其项目

从:

自动滚动:如果设置了此属性,则在释放时,旋转木马将自动滚动到最近的项目边框

看看它是如何工作的。使用
auto scroll
选项,当用户想要滑动到转盘中的下一个或上一个项目时,她不需要滑动到最后。部分刷卡就足够了,因为旋转木马将自动完成刷卡。删除
自动滚动
选项,按Run并尝试滑动旋转木马。您将看到,刷卡在您释放的位置停止

因此,
自动滚动
不是自动播放。但究竟如何实现自动播放呢?只需在
setInterval
函数中使用旋转木马方法(
next
first
getActiveIndex
)和属性(
itemCount

setInterval(function(){ 
  var carousel = document.getElementById('carousel');
  if (carousel.getActiveIndex() === carousel.itemCount-1)
     carousel.first();
  else
     carousel.next(); 
}, 1000);
var prev=function(){
var carousel=document.getElementById('carousel');
上一个转盘();
};
var next=函数(){
var carousel=document.getElementById('carousel');
carousel.next();
};
ons.ready(函数(){
var carousel=document.addEventListener('postchange',函数(事件){
console.log('更改为'+event.activeIndex)
});
});
setInterval(函数(){
var carousel=document.getElementById('carousel');
if(carousel.getActiveIndex()==carousel.itemCount-1)
carousel.first();
其他的
carousel.next();
}, 1000);

旋转木马
蓝色
黑暗的
橙色


auto scroll
option的意思是说“autoplay”?你的意思是说
auto scroll
option的意思是说“autoplay”?但是当我们只在HTML元素上包含auto scroll方法时,它就不起作用了,这是由onsen()预定义的,我们需要为它编写javascript代码。
auto scroll
可以在没有javascript的情况下工作。但是如果没有
swipeable
attribute它就不能工作,这不是问题所在<如果没有
swipeable
,代码>自动滚动就没有意义。我写
setInterval
不是为了让
自动滚动
工作
Auto scroll
属性用于与autoplay完全不同的任务。但是,当我们仅在HTML元素上包含Auto scroll方法时,它不起作用,这是由onsen()预定义的,我们需要为它编写javascript代码。
Auto scroll
在没有javascript的情况下工作。但是如果没有
swipeable
attribute它就不能工作,这不是问题所在<如果没有
swipeable
,代码>自动滚动就没有意义。我写
setInterval
不是为了让
自动滚动
工作<代码>自动滚动
属性用于与自动播放完全不同的任务。