快速移動滑鼠導致js 的mouseover,mouseout,mouseenter,mouseleave等事件(觸發動畫)反覆疊加的處理

來源:互聯網
上載者:User

如題,看了好多網友的文章,辦法是無效的,我驗證出了一種方案,共用一下:

hover方法是jquery封裝的js的mouseover,mouseout事件

 $("#footNav img").hover(function () {                if (!$(this).is(":animated")) {                    itsWidth = $(this).css("width");                    itsHeight = $(this).css("height");                    var itsWidthValue = itsWidth.substring(0, itsWidth.lastIndexOf('p'));                    var itsHeightValue = itsHeight.substring(0, itsHeight.lastIndexOf('p'));                    $(this).animate({ "width": itsWidthValue * 1.1 + "px", "height": itsHeightValue * 1.1 + "px" }, 200);                }            },function () {                $(this).animate({ "width": itsWidth, "height": itsHeight }, 200);            })

if (!$(this).is(":animated"))  //這是關鍵,判斷當前元素是不是正在執行動畫,如果沒有,可以執行下面的代碼,如果它本身正在執行,則不疊加執行

情境:當使用者快速移動滑鼠的時候,快得變態的時候,導致上一個事件還沒有執行完下一個又要執行了,疊加起來產生古怪的效果。

ps:本來沒有想到要這麼做的,變態的客戶成就了這一切......

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.