Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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 将动态ID添加到每个div,稍后调用它们_Jquery - Fatal编程技术网

Jquery 将动态ID添加到每个div,稍后调用它们

Jquery 将动态ID添加到每个div,稍后调用它们,jquery,Jquery,我生成了多个菜单,但它们在我的内容中有不同的菜单项和位置 对于每个“.ff_ftmenu”和“.ff_ftmenu_block”,都有一个单独的ID,因此ffmenu-0(例如)将匹配 我单击“.ff#ftmenu#块#ffmenu-0”并触发并打开“.ff#ftmenu#ffmenu-0”。这就是我的想法。但是如何将“ffmenu-”+索引”分配给循环,以便只打开一个循环 var tl = new TimelineMax({paused:true, reversed:true}); t

我生成了多个菜单,但它们在我的内容中有不同的菜单项和位置

对于每个“.ff_ftmenu”和“.ff_ftmenu_block”,都有一个单独的ID,因此ffmenu-0(例如)将匹配

我单击“.ff#ftmenu#块#ffmenu-0”并触发并打开“.ff#ftmenu#ffmenu-0”。这就是我的想法。但是如何将“ffmenu-”+索引”分配给循环,以便只打开一个循环

  var tl = new TimelineMax({paused:true, reversed:true});
  tl
    .staggerFromTo('.ff_ftmenu li', 1.5,
      {rotationX:-90, transformOrigin:"50% 0%"},
      {rotationX:0, ease:Elastic.easeOut}, 0.4);

  $('.ff_ftmenu').each(function(index){
    $(this).attr('id', 'ffmenu-' + index);
    //console.log( this.id );
  });

  $('.ff_ftmenu_block').each(function(index){
    $(this).attr('id', 'ffmenu-' + index);
  });

  $('.ff_ftmenu_block').each(function(index){
    $(this).click(function(index){
    $('.swp-col-1-3 .ff_ftmenu').toggleClass('open');

      if (!$('.swp-col-1-3 .ff_ftmenu').hasClass('open')) {
        TweenMax.to($('.swp-col-1-3 .ff_ftmenu'), 0.5, {opacity: 0});
        tl.reversed() ? tl.play() : tl.pause(0).reversed(true);
      }
      else {
        TweenMax.to($('.swp-col-1-3 .ff_ftmenu'), 1, {opacity: 1});
        tl.reversed() ? tl.play() : tl.pause(0).reversed(true);
      }

    });
  });

在本例中,使用jQuery来获取单击的元素并不需要每个元素。所以我想你可以代替我

$('.ff_ftmenu_block').each(function(index){
$(this).click(function(index){
$('.swp-col-1-3 .ff_ftmenu').toggleClass('open');

  if (!$('.swp-col-1-3 .ff_ftmenu').hasClass('open')) {
    TweenMax.to($('.swp-col-1-3 .ff_ftmenu'), 0.5, {opacity: 0});
    tl.reversed() ? tl.play() : tl.pause(0).reversed(true);
  }
  else {
    TweenMax.to($('.swp-col-1-3 .ff_ftmenu'), 1, {opacity: 1});
    tl.reversed() ? tl.play() : tl.pause(0).reversed(true);
  }

});
与(只是给你一个起点-想法)

$('.ff_ftmenu_block').on('click', function(){
    console.log($(this).attr('id');
    // move on from here with the id
    // and do whatever you want to do
});