延迟Jquery中的CSS功能?

前端之家收集整理的这篇文章主要介绍了延迟Jquery中的CSS功能?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何延迟jQuery中的CSS更改?这是我的代码
  1. $("document").ready(function() {
  2. $(".pressimage img").mouseenter(function() {
  3. $jq(this).css('z-index','1000');
  4. });
  5. $(".pressimage img").mouseleave(1000,function() {
  6. $jq(this).css('z-index','1');
  7. });
  8. });

我需要鼠标离开后约1/2秒的鼠标功能.

我使用一些其他jquery来使图像在鼠标悬停上展开.当它们展开时,它们相互覆盖,所以我需要动画图像的z指数高于另一个.然后当鼠标离开z-index时必须恢复正常.

上述代码的工作原理除了z-index在鼠标离开之后发生更改,因此动画没有时间完成.因此,我需要稍微延迟mouseleave功能.谢谢

UPDATE

这是我的网站:
http://smartpeopletalkfast.co.uk/ppr6/press

我把我的代码放在头上:

  1. $jq("document").ready(function() {
  2.  
  3. $jq(".pressimage img").mouseenter(function() {
  4. $jq(this).css('z-index','100');
  5. });
  6.  
  7. $jq(".pressimage img").mouseleave(function() {
  8. $jq(this).css('z-index','1');
  9. });
  10.  
  11. });

这段代码工作正常,但没有任何延迟.如果您将鼠标悬停在左上角的图像上,则可以正常工作,但一旦鼠标移开,就会在其下方的图像之后.
谢谢

解决方法

尝试这个:
  1. $(".pressimage img").mouseleave( function(){
  2. var that = this;
  3. setTimeout( function(){
  4. $(that).css('z-index','1');
  5. },500);
  6. });

猜你在找的jQuery相关文章