Show only on mobile works homepage only! Help please

I am quite new to WIX and to coding in general.

I have an element, Box10, attached to my header (not attached to any strip) and it is on “Hidden on Load”

I have the following code to show it only on mobile:

import wixWindow from ‘wix-window’;

$w.onReady( function () {
if (wixWindow.formFactor === “Mobile” &&
wixWindow.rendering.renderCycle === 1) {
$w(“#box10”).show();
}
} );

Hiding it from the desktop works like a gem, showing it on mobile only works as a gem, but only as long as I am on the Home Page. Once I navigate to another page, it is there on load but in a few seconds it vanishes.

I have this other code for two strips in the header, however, the item Box10 isn’t attached to any strip.

export function header1_viewportLeave(event, $w) {
$w(‘#WhiteHeader’).show(“fade”)
$w(‘#Headertransparent’).hide(“fade”)
//Add your code for this event here:
}

Where am I going wrong? Would appreciate some help!

Hi,
If the element is attached to the header, you should add the code to the site section and not the page section. Click here to learn more about it.

Best,
Tal.