Skip to content

Instantly share code, notes, and snippets.

@schmidtsonian
Last active December 20, 2015 01:29
Show Gist options
  • Select an option

  • Save schmidtsonian/6049484 to your computer and use it in GitHub Desktop.

Select an option

Save schmidtsonian/6049484 to your computer and use it in GitHub Desktop.
Image sequence object
var doSequence = {
theInterval: null,
currentIndex: 0,
count: 0,
pictureCount: 0,
indexOffset: 1,
element: null,
isIncrement: false,
interval: 60,
loop: false,
isPlay: false,
isDisplayLast: true,
onComplete: function(){ },
play: function(){
if(this.isPlay){ return false;}
this.element.css({"display": "none"});
this.element.eq(0).css({"display": "block"});
this.isPlay = true;
this.pictureCount = this.element.length;
if(this.isIncrement == true){
this.indexOffset = -1;
this.currentIndex = this.pictureCount-1;
}
var t = this
this.theInterval = setInterval( function(){
t.element.css({"display": "none"});
t.element.eq(t.currentIndex).css({"display": "block"});
t.currentIndex = t.currentIndex + t.indexOffset;
t.count++;
if( t.count == t.pictureCount ){
if(t.loop){
t.count = 0;
if(t.isIncrement == true){
t.currentIndex = t.pictureCount-1;
}else{
t.currentIndex = 0
}
}else{
t.isPlay = false;
t.currentIndex = 0;
if(t.isIncrement == true){
t.currentIndex = t.pictureCount-1;
}
t.count= 0;
clearInterval(t.theInterval);
t.onComplete();
if(t.isDisplayLast == false){
t.element.css({"display": "none"});
}
}
}
}, this.interval );
return true;
},
stop: function(){
this.isPlay = false;
this.currentIndex = 0;
this.count = 0;
clearInterval( this.theInterval);
},
destroy: function(){
clearInterval( this.theInterval);
this.element.css( {"display": "none"} );
},
test: function(){
// console.log(this.element);
}
}
@schmidtsonian
Copy link
Author

var sequenceTip9 = Object.create(doSequence);
sequenceTip9.element = $('#f-9 .back-right-bottom-left-top-sequence img');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment