Javascript If语句根据网页的宽度运行功能

时间:2016-04-17 04:32:29

标签: javascript jquery html css

我正在尝试在我的网页宽度介于700px和800px之间并且高度介于400px和500px之间时执行我的功能。

这是我的功能:

 $(document).ready(function() {
        function checkWidth() {
            var windowWidth = $(window).width();
            var windowHeight = $(window).height();

           if (windowWidth >= 700 && windowWidth <= 800 && windowHeight >= 400 && windowHeight >=500  ) { 

                 $('#text')
                .keyboard({ layout: 'qwerty' })
                .autocomplete({
                   source: availableTags
                })


               .addTyping();}        

                   }
        }

        // Execute on load
        checkWidth();
        // Bind event listener
        $(window).resize(checkWidth);

该函数有效但在if语句中不会执行。

0 个答案:

没有答案