Skip to main content
Inspiring
January 27, 2021
Answered

I'm stuck with show/hide objects with mouseover JS

Hi everyone,

I'm trying to show/hide some more than one text box with link with different objects with mouseover/out event.

 

When I do it with only one object I can get it to work with this:

 

document.getElementById("myTriggerSustain").addEventListener("mouseover", FunctionMouseOver);

function FunctionMouseMover() {

cp.show("TextSustain");

}

document.getElementById("myTriggerSustain").addEventListener("mouseout", FunctionMouseOut);

function FunctionMouseOut() {

cp.hide("TextSustain");

}

 

But when I try the code below with more than one object, I can't figure out why nothing happens:

 

window.addEventListener("mouseover", function(e) {

if(e.target.id == "MyTriggershapeSustain") {
document.getElementById("TextSustainc").cp.show(this.id);

};

 

if(e.target.id == "MyTriggershapePackaging") {
document.getElementById("TextPackagingc").cp.show(this.id);

};

 

if(e.target.id == "MyTriggershapeCSR") {
document.getElementById("TextCSRc").cp.show(this.id);

};

 

window.addEventListener("mouseout", function(e) {

 

if(e.target.id == "MyTriggershapeSustain") {
document.getElementById("TextSustainc").cp.hide(this.id);

};

 

if(e.target.id == "MyTriggershapePackaging") {
document.getElementById("TextPackagingc").cp.hide(this.id);

 

};

if(e.target.id == "MyTriggershapeCSR") {
document.getElementById("TextCSRc").cp.hide(this.id);

 

};

 

Regards

Jacob

This topic is closed to new replies. Start a new post to keep the conversation going.
TLCMediaDesign
TLCMediaDesignCorrect answer
Inspiring
January 27, 2021

You are treating the following line(s) like cp and cp.show are JS methods. They are part of the cp object:

document.getElementById("TextSustainc").cp.show(this.id);

So you need to use:

cp.show(this.id);

6 replies

TLCMediaDesign
TLCMediaDesignCorrect answer
Inspiring
January 27, 2021

You are treating the following line(s) like cp and cp.show are JS methods. They are part of the cp object:

document.getElementById("TextSustainc").cp.show(this.id);

So you need to use:

cp.show(this.id);

Translate
Inspiring
January 29, 2021

Hmm but how do I link "ObjectName" to cp.show(this.id);

 

 

Translate
TLCMediaDesign
Inspiring
January 29, 2021

In this statement, what is the element you are wanting to show?

 

if(e.target.id == "MyTriggershapeCSR") {
document.getElementById("TextCSRc").cp.show(this.id);

};

Translate
Stagprime2687219
Legend
January 27, 2021

I know this is not quite what you have going here but perhaps you'll find some usefulness from it. In my suggestion below, I have a box to serve as the hover object named "box" and four other items on stage named "obj1", "obj2", "obj3", and "obj4". This is placed in the slide onEnter action.

 

$("#box").hover(function() {
cp.show("obj1");
cp.show("obj2");
cp.show("obj3");
cp.show("obj4");
},
function() {
cp.hide("obj1");
cp.hide("obj2");
cp.hide("obj3");
cp.hide("obj4");
});

Translate
Inspiring
January 29, 2021

Thanks G,

It worked

Translate