当鼠标在页面加载时悬停在框上时,停止运行jQuery

时间:2017-04-10 14:01:53

标签: javascript jquery mouse

我有这个jQuery:

byte[] cipherBytes = cipher.doFinal(input);
System.out.println("cipher: " + new String(cipherBytes));
returnValue += new String(cipherBytes);

String cipherText = new String(cipherBytes);
byte[] reCipherBytes = cipherText.getBytes();

cipher.init(Cipher.DECRYPT_MODE, privKey);
byte[] plainText = cipher.doFinal(reCipherBytes);
System.out.println("plain : " + new String(plainText));

然而,我遇到一个问题,如果我加载页面,并且我的鼠标已经在滑动框的位置,那么框将向上滑动并且切换将反转...所以 - 切换当我不悬停时,我想显示当我悬停显示时,当我这样做时它隐藏起来,而不是反过来......!

如果jQuery在页面加载时已经定位在它上面以阻止此切换被反转,我该如何让jQuery忽略它?我已经看过这里的其他问题了,解决方案似乎没有用。

希望你能提供帮助。

1 个答案:

答案 0 :(得分:0)

根据.hover here的规范,我建议同时使用hoverIn和hoverOut,然后使用slideToggleslideDown而不是slideUp。如:

jQuery('.slidey').hover( 
  function(){
    if (jQuery(window).width() > 1151) {
      jQuery(this).children('.post-content').stop().slideDown(180);
    }
  },
  function(){
    if (jQuery(window).width() > 1151) {
      jQuery(this).children('.post-content').stop().slideUp(180);
    }
  }
);

此外,请点击此处See Additional Notes

  

在jQuery 1.8中不推荐使用,在1.9中删除:名称“hover”用作字符串“mouseenter mouseleave”的简写。它为这两个事件附加单个事件处理程序,并且处理程序必须检查event.type以确定事件是mouseenter还是mouseleave。不要将“hover”伪事件名称与.hover()方法混淆,后者接受一个或两个函数。