【问题标题】:if statement including hover() and window widthif 语句包括 hover() 和窗口宽度
【发布时间】:2017-11-08 02:20:31
【问题描述】:

我对这一切都很陌生,我现在有这个:

$( 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”。

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

【问题讨论】:

    标签: javascript if-statement hover width jquery-hover


    【解决方案1】:

    你需要把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)
          }
        });
      }
    
    });
    

    【讨论】:

    • 它不起作用,伙计.. 另一种解决方案?还是网上的例子?
    • 你能告诉我你到底想达到什么目标吗?虽然我将 if 语句中的条件更改为更合乎逻辑的表示形式,从 $(window).width() < 480$(window).width() > 480
    • 如何查看更新的代码?我只看到旧代码
    • 如果你分叉了代码,请分享我的分叉代码
    • 抱歉耽搁了,这里是链接codepen.io/anon/pen/VWpvRx?editors=0010
    猜你喜欢
    • 2012-08-18
    • 1970-01-01
    • 2018-07-02
    • 2021-06-27
    • 2013-03-25
    • 1970-01-01
    • 2014-11-11
    相关资源
    最近更新 更多