I’ve really looked everywhere for this and I can’t find any concrete examples of how to do this.
I want to hide certain elements based on the users screen size. For example I’d like to hide a navigation menu and show a button that opens a lightbox instead if the users screen is say smaller than 1500px in width. Is this possible?
I’ve tried doing it with wixWindow but I can’t seem to get the code to work or I’m completely doing it wrong… I’m no expert in code so I’d really be happy for any help I can get.
Final question: Is there a way for the code to fetch the browsers screen size in real time? As in if they resize their screen the code will detect it and execute the code again?
Also, how did you know what to put in the code? I tried finding the set up online but really couldn’t. Is there any specific sites that explain how to set up the code and in what order everything should be?
@josef ,
Currently you can’t use Corvid to set an event listener that detects screen size change.
However you can check size change every x millisecond using setInterval (I don’t know if it has any effect on the general performance, you’ll have to test it:
import wixWindow from 'wix-window';//at top of the code page
$w.onReady(() => {
setInterval(() => {detectScreenSizeChange();},100);
});
function detectScreenSizeChange(){
wixWindow.getBoundingRect()
.then(winInfo => {
let winWidth = winInfo.window.width;
if (winWidth < 1500){
//code
} else {
//code
}
});
}
As for how to understand how to use Corvid - there’s the full API documentation: Velo API Reference - Wix.com
and you can search the forum as well (+ experience)
I am trying to set up a code which will HIDE my site HEADER - in MOBILE view - when the orientation is HORIZONTAL …
Found your code example above and tried to modify it for my purpose, as follows -
// Hide Header 1 if Mobile-View is HORIZONTAL
$w.onReady(() => {
wixWindow.getBoundingRect()
.then(winInfo => {
let winHeight = winInfo.window.height;
let winWidth = winInfo.window.width;
let headerStrip1IsCollapsed = $w('#columnStrip14').collapsed;
/// '#columnStrip14' is the primary container on my header - I am referencing that since when I try to reference "#header1" an ERROR message says "collapsed is not available on #header1" ///
let headerStrip1IsExpanded = $w('#columnStrip14').expanded;
if (winWidth > winHeight){
headerStrip1IsCollapsed
} else {
headerStrip1IsExpanded
}
} );
});
//
But this is NOT making it happen! (Even though the code panel is NOT showing any Errors)
Where am I going wrong?
Can it actually be achieved, to begin with?
(I am a noob - who’s basically groping in the dark!)
First all, you should know that it won’t work if you change the orientation after the page got loaded (and I’m not sure it’ll work at all on some of cell-phones).