JQUERY 简写
答案:2 悬赏:20
解决时间 2021-02-16 20:25
- 提问者网友:愿为果
- 2021-02-16 13:17
JQUERY 简写
最佳答案
- 二级知识专家网友:鱼芗
- 2021-02-16 14:13
//你在所有div下写一个共同的类,例如 .class_select
$(function(){
var div_index;//声明div最后数字为多少
var div_name;
$(".class_select").each(function(){
div_name = $(this).attr("id");
div_index = div_name.subStr(div_name.length-1,1);
$("#"+div_name).animate({top:dh+div_index,left:dw+div_index}, 500, 'swing');
});
});追答
追问:加了.class_select同样也无法运行!
追答:请坐代码调试 $(".class_select").each(function(){
alert(123);//看看是否弹出代码
});
追问:还是不行,能发段完整的源码案例么?
$(function(){
var div_index;//声明div最后数字为多少
var div_name;
$(".class_select").each(function(){
div_name = $(this).attr("id");
div_index = div_name.subStr(div_name.length-1,1);
$("#"+div_name).animate({top:dh+div_index,left:dw+div_index}, 500, 'swing');
});
});追答
追问:加了.class_select同样也无法运行!
追答:请坐代码调试 $(".class_select").each(function(){
alert(123);//看看是否弹出代码
});
追问:还是不行,能发段完整的源码案例么?
全部回答
- 1楼网友:旧脸谱
- 2021-02-16 14:58
要有共同性才行,
选择器可以用样式名,所有需要animate的div都写上一样的样式名,比如 class='div_animate',
然后:
$(".div_animate").each(function(){
var int_top = 10;//主要是几个div这里的 top, left最终的值有什么联系没有
var int_left = 10;
$(this).animate({top: int_top,left:int_left}, 500, 'swing');
}
这样,有多少个div需要animate都可以用这段代码了,有疑问联系方式联系。
选择器可以用样式名,所有需要animate的div都写上一样的样式名,比如 class='div_animate',
然后:
$(".div_animate").each(function(){
var int_top = 10;//主要是几个div这里的 top, left最终的值有什么联系没有
var int_left = 10;
$(this).animate({top: int_top,left:int_left}, 500, 'swing');
}
这样,有多少个div需要animate都可以用这段代码了,有疑问联系方式联系。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯