如果窗口宽度小于768px,请勿触发功能 [英] If window is less than 768px wide, don't fire function

查看:326
本文介绍了如果窗口宽度小于768px,请勿触发功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果页面加载和调整大小的窗口宽度小于768px,我不想激活 showCover()函数。使用下面的代码,即使窗口小于768px,它仍然被触发。

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');
        });
    }


推荐答案

我会走另一条路周围:

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');
        }
    });

});

这篇关于如果窗口宽度小于768px,请勿触发功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆