3
I would like all actions programmed with Javascript to be effective when the $(window).width() <= 800 to avoid conflicts between Mobile layout and desktop. But the truth is that it runs out of CSS but the actions (events) defined in Javascript continue to happen and I would like it to stop everything, as if nothing is set in jQuery. I have the following code but it doesn’t work:
HTML:
....
<link rel="stylesheet" media='screen and (min-width: 801px)' href ="css/styles.css">
<link rel="stylesheet" media='screen and (max-width: 800px)' href ="css/stylesMob.css">
<!-- HTML -->
....
//JQUERY
....
//isto no final da página
if ($(window).width() < 800) {
$('*').off();
}
$(window).resize(function(){
if ($(window).width() < 800) {
$('*').off();
}
})
For a more detailed view here is the website.
What makes the jQuery you want to block? are click events or also
change? If you click only, you can use CSS Pointer Events... (this link does not work)– Sergio
All because I will use the same elements (id’s and classes) for window <= 800. and I wouldn’t want there to be any conflicts, the only thing that will change is the css file. I would like for window < 800 to be a new jquery
– Miguel
"A new jQuery" seems difficult and/or laborious. In this case the safest is to have a flag and check this condition on all pieces of code. If you put the jQuery that you want to "hang up" the question becomes clearer.
– Sergio
Is it possible to specify, as I did with the css files above, . js files for different window sizes? If it’s possible, it sounds like a great solution. Or wrap all of my js code in the condition: 'if(($window).width() > 800) { // All code made for desktop } Else { //Mobile layout }'
– Miguel
Miguel added an answer. Your suggestion to do
if(($window).width() > 800) { // Todo o codigo feito para desktop } else { //layout Mobile }is also an alternative, orpointer-event: none;within a media query. Put jQuery here to see which of the variants is the best and easiest to maintain.– Sergio