Stop iteration when end of data objects are reached

爱⌒轻易说出口 提交于 2019-12-25 04:13:13

问题


Using the TweenMax library, I am unable to kill or stop a delayedCall when the end of the data object is reached instead of looping because it is a self calling function.

https://jsfiddle.net/rdzo13cf/6/

In the example above the last item in the data is not displayed.


回答1:


Actually it's because you are incrementing your iter variable before you set it. Which causes it to not display the last item, you want to increment after:

function setContent() {
    element.html(data[iter].content);
    iter = iter >= data.length-1 ? -1 : iter;
    iter = iter + 1;    
}

Basically you are going over indexes [1,2,3] when you want to be going over [0,1,2].

Fiddle Example



来源:https://stackoverflow.com/questions/32997633/stop-iteration-when-end-of-data-objects-are-reached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!