removeClass不删除手机上的动画类吗?

时间:2018-11-06 17:05:34

标签: javascript jquery

(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做错什么。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

我能够通过稍微更改代码来使其工作:

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

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

谢谢大家发表评论!