2017-07-23 34 views
-2

我一直在設計與網頁中的一些動畫網頁信息圖表添加很多的div。所以我添加了一些JavaScript代碼,以便在用戶在屏幕上觸及動畫時觸發動畫。如何在JavaScript代碼

我的問題是如何在JavaScript句子添加許多div名字?

該div的名稱是「box_info_a」,我只需要添加更多,但不知道如何。

這是代碼:

$(function() 
    var $window = $(window), 
     win_height_padded = $window.height() * 1.1, 
     isTouch = Modernizr.touch; 
    if (isTouch) { 
     $('.revealOnScroll').addClass('box_info_a'); 
    } 
    $window.on('scroll', revealOnScroll); 
    function revealOnScroll() { 
     var scrolled = $window.scrollTop(), 
      win_height_padded = $window.height() * 1.1; 
     // Showed... 
     $(".revealOnScroll:not(.box_info_a)").each(function() { 
      var $this = $(this), 
       offsetTop = $this.offset().top; 
      if (scrolled + win_height_padded > offsetTop) { 
       if ($this.data('timeout')) { 
        window.setTimeout(function() { 
         $this.addClass('box_info_a ' + $this.data('animation')); 
        }, parseInt($this.data('timeout'), 10)); 
       } else { 
        $this.addClass('box_info_a ' + $this.data('animation')); 
       } 
      } 
     }); // Close Showed... 
     // Hidden... 
     $(".revealOnScroll.box_info_a").each(function (index) { 
      var $this = $(this), 
       offsetTop = $this.offset().top; 
      if (scrolled + win_height_padded < offsetTop) { 
       $(this).removeClass('box_info_a lightSpeedIn') 
      } 
     }); 
    } 
    revealOnScroll(); 
}); 

回答

0

只是這樣做:

$(document).ready(function() { 
 
    $('#trigger').click(function() { 
 
    $('#target').addClass("oneClassToAdd anotherClassToAdd"); 
 
    }); 
 
});

所有您需要做的就是把兩個班在括號中。

+0

可以找到一個例子[here](http://liveweave.com/r2efMu)。只需點擊「Hello Weaver」即可添加兩個課程。 –