user783146
user783146

Reputation: 1565

Is there a way to initialize and deinitialize jquery plugins based upon the viewport size?

Basically I want to load a particular jquery plugin on smaller viewports, and then on larger ones deinitialize it and initialize a different one?

Upvotes: 1

Views: 484

Answers (1)

weir
weir

Reputation: 4771

This does not account for window resizing, but perhaps it will set you in the right direction.

$(document).ready(function() {
    var viewportWidth = $(window).width();
    var viewportHeight = $(window).height();

    var widthThreshold = 1000;
    var heightThreshold = 800;

    var scriptUrl;
    if (viewportWidth > widthThreshold &&
        viewportHeight > heightThreshold){
        scriptUrl = "plugin1.js";
    }
    else {
        scriptUrl = "plugin2.js";
    }
    $.getScript(scriptUrl);
};

Upvotes: 2

Related Questions