Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Animation(elem){
- // code tests the application of js arrow function
- // date August 18, 2018
- this.elemid = document.querySelector('#'+elem)
- }
- Animation.prototype = {
- constructor: Animation,
- color: ['red', 'blue', 'black', 'yellow'],
- display:function(){
- var len = this.color.length;
- var index = 0;
- setInterval(()=>{
- if(index < len){this.elemid.style.backgroundColor = this.color[index];
- index++;
- }else{
- index =0;
- this.elemid.style.backgroundColor = this.color[index]
- }
- },3000);
- }
- };
- var testDiv = new Animation('test');// create instance of the class
- testDiv.display();
- var test2 = new Animation('test2');// create another instance
- test2.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement