Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

javascript - 如何在面向对象编程中重新编写JavaScript代码? [关闭](How can i re write my JavaScript code but in Object Oriented Programming? [closed])

I started Javascript 2 weeks ago but i just heard about OOP, i was already working on a project for fun, but now i wanna re write the same code but in OOP, i watched a lot of tutorials, i kinda understand it but i dont really understand how i can translate it in more "practical code" how can i do that ?

(我两周前开始使用Javascript,但我刚刚听说过OOP,我已经在做一个有趣的项目,但是现在我想重新编写相同的代码,但是在OOP中,我看了很多教程,我有点理解,但是我不知道真正了解如何将其翻译成更多的“实用代码”,我该怎么做?)

If someone could give a example with my slider code, not all of it just a little part so i can understand the "concept".

(如果有人可以用我的滑块代码举一个例子,那么并非全部都是一小部分,因此我可以理解“概念”。)

//Images
const images =["images/slide1.jpg", "images/slide2.jpg", "images/slide3.jpg"];
let numImage = 0;
const imageDebase = document.getElementById("imageActuelle").src = images[numImage];


//Change image every 5sec

let temps = setInterval(changemementImages, 5000);

function changemementImages(){
    if(numImage >= 2){
        numImage-=2;
        document.getElementById("imageActuelle").src = images[numImage];
    }
    else if (images[0]){
        document.getElementById("imageActuelle").src = images[++numImage];  
    };
};


//Buttons

function boutonDroite(){
    i = 0;//reset la barre de progression
    if (numImage >= 2){
        numImage -= 3;
    }
    document.getElementById("imageActuelle").src = images[++numImage];  
    //reset le timer
    clearInterval(temps);
    temps = setInterval(changemementImages, 5000);
};



function boutonGauche(){
    i = 0; //reset la barre de progression 
    if (numImage <= 0){
        numImage += 3;
    }
    document.getElementById("imageActuelle").src = images[--numImage];
    //reset le timer
    clearInterval(temps);
    temps = setInterval(changemementImages, 5000);
};


//Progression bar

const prog = document.getElementById('contenubarredeprogression');
var i = 0;
var progression = setInterval(barredeprogression, 50);

function barredeprogression (){
    i++;
    prog.style.width = i + "%";
    if (i >= 100){
        i = 0;
    }

};
  ask by Gobi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...