if 语句包括 hover() 和 window 宽度

if statement including hover() and window width

我确定这一切都是新的,我现在有这个:

$( document ).ready(function() {

   $('.item').hover(
      function(){
          $(this).find('.hola').slideDown(250); //.fadeIn(250)
      },
      function(){
          $(this).find('.hola').stop(true, false).slideUp(250); //.fadeOut(205)
      }
   );

});

我需要在小屏幕上禁用此代码,这是我希望它工作的代码:

你可以在 codepen

中观看我的 code

IMAGE OF DISPLAY IN SMALL SCREEN

我不想发生这种情况,我需要在悬停时禁用“.hola”。

我尝试禁用它,但我没有实现它

你需要把if语句移到事件之前

$(document).ready(function(){

  if ($(window).width() > 480) {
    $(".item").hover(function(){
      function(){
          $(this).find('.hello').slideDown(250); //.fadeIn(250)
      },
      function(){
          $(this).find('.hello').slideUp(250); //.fadeOut(205)
      }
    });
  }

});