Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - remove div by class when the screen is smaller than 1350px

Tags:

html

jquery

width

I am working on a site with parallax scrolling that consists of 4 'pages' on which you can scroll trough by pressing an up or down button.

The first 'page' contains a video background. There is no need for this 'page' to be visible on tablet and mobile. I can hide this 'page' by using media queries, but this breaks the parallax scrolling functionality as the script of this functionality still sees the hidden div.

So to not show the page, I thought the best way was to fully remove the div. Since this can't be done by Media Queries i'm searching for a way with jQuery to remove the div by class when the screens width is smaller than 1350px

Any idea will be appreciated!

like image 516
Brendan Avatar asked Dec 04 '25 14:12

Brendan


1 Answers

You should use window.matchMedia:

$(function(){
    if (window.matchMedia("(max-width: 1350px)").matches) {
        $('div.myClass').remove();
    }
});

CanIUse

Polyfill

like image 165
A. Wolff Avatar answered Dec 07 '25 03:12

A. Wolff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!