Pregunta

If the window width on page load AND resize is less than 768px, I don't want to fire the showCover() function. With the below code, even when the window is less than 768px, it's still being fired.

    function ipsThemeViewer() {

        jQuery(window).resize(function() {
           if ( jQuery(window).width() < 768 ) return false;
           showCover();
        }).resize();

    }

    function showCover() {
        jQuery('#ipsThemeViewerScreen').hover(function () {
            var t = jQuery(this);
            jQuery('.cover').stop().fadeIn('fast');
        }, function () {
            var t = jQuery(this);
            jQuery('.cover').stop().fadeOut('fast');
        });
    }
¿Fue útil?

Solución

I would go the other way around:

jQuery(function($) {  // DOM READY AND SECURE $ ALIAS

    var winIsSmall;

    function testWinSize(){
        winIsSmall= $(window).width() < 768; // BOOLEAN
    }

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

    $('#ipsThemeViewerScreen').hover(function () {            
        if(winIsSmall){
            // need something here?
        }else{
            $('.cover').stop().fadeToggle('fast');
        }
    });

});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top