If statement flex slider if mobile

I was trying to make an if else statement for my flex slider settings. But now the will both play autoplay on screen smaller then and bigger then 768. // Setup for slider single page var winIsMobile;

function WinSize(){
    winIsMobile = $(window).width() < 768; // Boolean
} 

$(window).on("load resize", WinSize);

$.fn.flexMobile = function(){
    if (WinSize){
        $(this).flexslider({
            animation: "slide",
            slideshow: true
        });
    } else { 
        $(this).flexslider({
            animation: "slide",
            slideshow: false
        });
    }

}

$('#portfolio-single .flexslider, #cmyk .flexslider').flexMobile();

Answers


You need to do two things in order for this to work. Firstly in your WinSize function instead of assigning your boolean value to a variable you need to actually return it:

function WinSize(){
    return $(window).width() < 768; // Boolean
}

Secondly in your if statement you need to properly call this function (don't forget the brackets):

if (WinSize()){...

Try this and if the rest of code is configured correctly it should work.


Need Your Help

Why do we need to use import 'babel-polyfill'; in react components?

reactjs webpack redux

I wonder if we user babel loader + all the presets, why do we need to include babel-polyfill anyway into our components? I just think that babel-loader should do all the job itself.

How to pass property as a parameter in order to use the same function to modify different properties

c# properties parameters linq-to-objects

I've found similar questions asked before but the answers I've seen have been specific to the example given by the person or workarounds for that person's example, not a general solution.