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?
J.D
February 12, 2020, 9:17pm
2
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();
})
}
})
Thank you a lot! A real MVP.
J.D
February 12, 2020, 9:47pm
4
@allu112apina you’re welcome
gemats
December 13, 2020, 7:38pm
5
@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.
J.D
December 13, 2020, 10:07pm
6
@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();}