jQuery toggle class

后端 未结 2 1338
猫巷女王i
猫巷女王i 2020-12-03 19:02

I\'m having trouble adding in jQuery\'s toggleClass function into the rest of my code. The page has several HTML5 audio tags on it which are controlled via jQuery. I attempt

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 19:38

    I would use .addClass() and .removeClass(), as it'll clean up your code quite a bit and allow you to use CSS to perform all that layout work:

    $('thumbnail').toggle(function(){
        $('.play', this).removeClass('pausing');
        $('.play', this).addClass('playing');
    }, function(){
        $('.play', this).addClass('pausing');
        $('.play', this).removeClass('playing');
    });
    

提交回复
热议问题