Sketchfab Forum

Addeventlistener problems toggling on/off.... help needed!

viewer-api

(Ixtatica) #1

Hello. I have a html page with javascript that I can't get to work. I'm a complete rookie and it is probably a simple solution. I have adjusted a readymade script.

In line 156:

// Add button event
buttonLine_3.addEventListener( 'click', function() {
if(this.style.backgroundColor === 'green') {
this.style.backgroundColor = 'red';
// additional commands
}
else {
this.style.backgroundColor = 'green';
// additional commands
}
});

This setup work on a testpage where I copied the code snippet from. The button toggle color when I click. But in my script it just goes to red and then not back to green when I click again.

Could someone tell me what is wrong? Could someone fix my problem? Thanks.

Link to html file:

3D Model page v02.html (16.8 KB)


(Ixtatica) #2

The buttons should be used with the hide/show api command.