Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Live change based on device width Reply To: Live change based on device width

#177689
Senff
Participant

@Soronbe is right, you may want to look into media queries to make things look different based on screen size. However, if you really need to use jQuery cause (for whatever reason) you have to add something to the DOM, you might want to use this:


$(document).ready(function () {awesomeFunction();});
$(document).resize(function () {awesomeFunction();});

function awesomeFunction() {
    $screensize = $(window).width();
    if ($screensize > 1024) {
        $('#menu .nav > li.categories_hor > div > .column:nth-child(6n)').after('<div class="clearfix visible-lg-block"></div>');
    } else {
        $('#menu .nav > li.categories_hor > div > .column:nth-child(4n)').after('<div class="clearfix visible-lg-block visible-md-block"></div>');
    }
}