Search code examples
jqueryinstagramfeed

How to change instafeeds limit on certain widths


I can change the Instafeed limit by just changing the numbers in the script. I was wondering if there was a way to write an if statement of a window width of < 600 or some number and set the limit to 4 then an else if for 800 then change the limit and so on. Sort of like break points you would write in CSS. Here is my script.

var feed = new Instafeed({
            get: 'tagged',

            limit: 12,
            resolution: "standard_resolution",
            after: function() {
                external();
        }
    });
        feed.run();
        function external(){
    jQuery(document).ready(function($){
        $('#instafeed a').attr('target','_blank');
    });


}

Solution

  • Easy, check window width. Try

    var InstafeedLimit = 12; // default
    
    if($(window).width() < 800) {
        InstafeedLimit = 4; // change limit on screens less than 800px 
    }
    
    var feed = new Instafeed({
                get: 'tagged',
                limit: InstafeedLimit,
                resolution: "standard_resolution",
                after: function() {
                    external();
            }
        });
            feed.run();
            function external(){
        jQuery(document).ready(function($){
            $('#instafeed a').attr('target','_blank');
        });
    
    }