Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery子项没有设置动画_Jquery_Jquery Animate - Fatal编程技术网

jquery子项没有设置动画

jquery子项没有设置动画,jquery,jquery-animate,Jquery,Jquery Animate,我只想为div的特定子级设置动画,但如果指定类,则不会设置动画。如果我指定父类,就可以了 查看JSFIDLE: HTML: 左 赖特 AAA 111 22222 33333 var=0; var=0; $(“#左”)。单击(函数(){ leftCards='-'+$(“.targetchild”).width()+'px'; $(“.targetchild”).stop().animate({ “左”:左卡片 }); $('.tarWidth').text($(“.targetchild”).w

我只想为
div
的特定子级设置动画,但如果指定类,则不会设置动画。如果我指定父类,就可以了

查看JSFIDLE:

HTML:

左
赖特
AAA
111
22222
33333
var=0;
var=0;
$(“#左”)。单击(函数(){
leftCards='-'+$(“.targetchild”).width()+'px';
$(“.targetchild”).stop().animate({
“左”:左卡片
});
$('.tarWidth').text($(“.targetchild”).width()+'px');
});
//以相反方向启动动画
$(“#右”)。单击(函数(){
rightCards='+'+$(“.targetchild”).width()+'px';
$(“.targetchild”).stop().animate({
“左”:右卡片
});
$('.tarWidth').text($(“.targetchild”).width()+'px');
});

您需要为儿童设置位置,否则它是静态的:


确切地说,你想在点击按钮时制作什么动画?只有targetchildGot类的孩子才可以查看A.Wolff的答案。。有效:)
    <button id="left">Left</button>
<button id="right">Right</button>
<div class="target">
    <div id="targetDiv1" class="targetchild_no_animate" style="overflow:auto;height:20px;">AAA</div>
    <div id="targetDiv2" class="targetchild" style="overflow:auto;height:20px;">111</div>
    <div id="targetDiv3" class="targetchild" style="overflow:auto;height:20px;">22222</div>
    <div id="targetDiv4" class="targetchild" style="overflow:auto;height:20px;">33333</div>
     </div>
    <div class="tarWidth" style="top:100px;position:relative"></div>

 var rightCards = 0;
 var leftCards = 0;

 $("#left").click(function () {
   leftCards = '-' + $(".targetchild").width() + 'px';
   $(".targetchild").stop().animate({
     'left': leftCards
   });
   $('.tarWidth').text($(".targetchild").width() + 'px');
 });

    // Start animation in the opposite direction
 $("#right").click(function () {
   rightCards = '+' + $(".targetchild").width() + 'px';
   $(".targetchild").stop().animate({
     'left': rightCards
   });
   $('.tarWidth').text($(".targetchild").width() + 'px');
 });
div.targetchild {
    position:relative;
}