gpt4 book ai didi

javascript - removeClass 不删除移动设备上的动画类?

转载 作者:行者123 更新时间:2023-12-03 00:47:36 27 4
gpt4 key购买 nike

(function removeAnimation() {
var $window = $(window),
$html = $('html');
if ($window.width() < 600) {
alert("working");
$('.animated').removeClass('animated');
$('.slideInLeft').removeClass('slideInLeft');
$('.fadeIn').removeClass('fadeIn');
$('.fadeOut').removeClass('fadeOut');
$('.bounce').removeClass('bounce');
}
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hero-content">

<div class="hero-text">
<h1 class="animated slideInLeft">Ryan Klotz</h1>
<h4 class="animated slideInLeft">Front-End Web Developer</h4>
</div>

<div class="animated fadeIn">
<div class="animated fadeOut">
<span
class="animated bounce glyphicon glyphicon-circle-arrow-down" aria-label="Scroll Down"> </span>
</div>
</div>

</div>

我试图在用户移动时从内容中删除动画(这似乎会导致一个奇怪的错误)。我似乎无法弄清楚我对 jQuery 做错了什么。非常感谢任何帮助!

最佳答案

我可以通过稍微改变我的代码来让它工作:

$( document ).ready(function() {      
var isMobile = window.matchMedia("only screen and (max-width: 760px)");

if (isMobile.matches) {
$('.animated').removeClass('animated');
$('.slideInLeft').removeClass('slideInLeft');
$('.glyphicon').remove();
}
});

感谢大家的评论!

关于javascript - removeClass 不删除移动设备上的动画类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53176655/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com