如何在JavaScript代码中添加多个div
我一直在设计一个网页信息图,其中包含一些动画。所以我添加了一些JavaScript代码,以便在用户到达屏幕时触发动画 我的问题是如何在JavaScript语句中添加许多如何在JavaScript代码中添加多个div,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我一直在设计一个网页信息图,其中包含一些动画。所以我添加了一些JavaScript代码,以便在用户到达屏幕时触发动画 我的问题是如何在JavaScript语句中添加许多div名称 div的名称是“box\u info\u a”,我只需要再添加一些,但不知道如何添加 代码如下: $(function() var $window = $(window), win_height_padded = $window.height() * 1.1, isTouch
div
名称
div的名称是“box\u info\u 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();
});
$(函数()
变量$window=$(window),
win_height_padded=$window.height()*1.1,
isTouch=现代化触摸;
如果(isTouch){
$('.revelonscroll').addClass('box_info_a');
}
$window.on('scroll',revealunscroll);
函数revealOnScroll(){
var scrolled=$window.scrollTop(),
win_height_padded=$window.height()*1.1;
//显示。。。
$(“.revealOnScroll:not(.box\u info\u a)”)。每个(函数(){
变量$this=$(this),
offsetTop=$this.offset().top;
如果(滚动+赢得高度填充>偏移){
if($this.data('timeout')){
setTimeout(函数(){
$this.addClass('box\u info\u a'+$this.data('animation');
},parseInt($this.data('timeout'),10));
}否则{
$this.addClass('box\u info\u a'+$this.data('animation');
}
}
})//Close显示。。。
//隐藏的。。。
$(“.revelonscroll.box\u info\u a”)。每个(函数(索引){
变量$this=$(this),
offsetTop=$this.offset().top;
如果(滚动+赢得高度填充<偏移){
$(this.removeClass('box\u info\u a lightSpeedIn'))
}
});
}
revealunscroll();
});
只需执行以下操作:
$(文档).ready(函数(){
$(“#触发器”)。单击(函数(){
$(“#target”).addClass(“一个类添加到另一个类添加”);
});
});代码>可以找到一个示例。只需单击“Hello Weaver”,即可添加两个类。