onMouseOut and OnMouseIn needed inside if statement

Im trying to run a code like this:

if(wixWindow.formFactor === "Desktop"){
export function box6_mouseIn(event) {
if( $w("#box6").collapsed ) {
$w("#box6").expand();
}
else {
$w("#box6").collapse();
}
}
export function box6_mouseOut(event) {
if( $w("#box6").collapsed ) {
$w("#box6").expand();
}
else {
$w("#box6").collapse();
}
}
}

It is ofcourse saying that only can use export on top level…

How can I make so that the code only runs on Desktop?

Instead of using export function do something like this:

import wixWindow from 'wix-window';
$w.onReady(() => {
    if(wixWindow.formFactor === "Desktop"){
    $w("#box6").onMouseIn(event => {
     $w("#box6").collapsed ? $w("#box6").expand() : $w("#box6").collapse();
       })
$w("#box6").onMouseOut(event => {
    $w("#box6").collapsed ? $w("#box6").expand() : $w("#box6").collapse();
        })
    }
})
1 Like

Thank you a lot! A real MVP.

@allu112apina you’re welcome :slight_smile:

@jonatandor35 Hi there, would you mind please explaining this part of your code above? Can I use it with less than 3 ‘arguments’? I try to delete the first part (the ‘collapse’) but it can’t stand alone.

$w("#box6").collapsed ? $w("#box6").expand() : $w("#box6").collapse();
       })

Where can I find some more reference with this usage?

Thanks.

@gemats see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

It can be written as:

if($w("#box6").collapsed){$w("#box6").expand();} else {$w("#box6").collapse();}
1 Like