Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
Javascript 一次自动播放两个引导弹出窗口,而不是一个_Javascript_Jquery_Twitter Bootstrap - Fatal编程技术网

Javascript 一次自动播放两个引导弹出窗口,而不是一个

Javascript 一次自动播放两个引导弹出窗口,而不是一个,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,目前,它在循环中一次自动播放一个Popover。然而,我想让它自动播放2弹出一次。当然,在循环中 将添加更多的弹出窗口。我该怎么做 HTML 我有一个你正在寻找的工作实例。您可以指定要同时显示的popOver项目的数量,它将继续沿着链向下,并在每个间隔内循环(如果需要)。我改变的第一件事是popOver类名。它们现在从p0-p1-p2-p3开始,使其与0索引数组一致。这使得代码中的-1更少。所以Html看起来像: <div class="container"> <a hre

目前,它在循环中一次自动播放一个Popover。然而,我想让它自动播放2弹出一次。当然,在循环中

将添加更多的弹出窗口。我该怎么做

HTML


我有一个你正在寻找的工作实例。您可以指定要同时显示的popOver项目的数量,它将继续沿着链向下,并在每个间隔内循环(如果需要)。我改变的第一件事是popOver类名。它们现在从p0-p1-p2-p3开始,使其与0索引数组一致。这使得代码中的-1更少。所以Html看起来像:

<div class="container">
  <a href="#" title="Header" class="myclass p0" data-toggle="popover" data-trigger="hover" data-placement="left" data-content="Some content">Hover Left</a> | 
  <a href="#" title="Header" class="myclass p1" data-toggle="popover" data-trigger="hover" data-placement="right" class="myclass" data-content="Some content">Hover Right</a> | 
  <a href="#" title="Header" class="myclass p2" data-toggle="popover" data-trigger="hover" data-placement="top" data-content="Some content Yo Bestie">Click Me</a> | 
  <a href="#" title="Header" class="myclass p3" data-toggle="popover" data-trigger="hover" data-placement="bottom" data-content="Some content Yo Bestie">Click Me</a>
</div>
这方面的javascript是:

$(document).ready(function(){
var time = 1000;
var popOverLength = $('.myclass').length;
var popOverIdx = 0;
var numConcrPopOver = 2;
var fun = setInterval(function(){
    var popsToShow = []; //Array that will hold index of popOvver items to show
  var popsToHide = []; //Array that will hold index of popOvver items to hide
  //Loop for the number of simultanious popOver you want to show
  for(var popNum=0; popNum<numConcrPopOver; popNum++){
    var currPopIdx = popOverIdx+popNum; //Index o fthe current  popOver to show
    popsToShow.push(currPopIdx%popOverLength); //Alwyas mod index to keep within lenght of popOver items
    var hidePopIdx = popOverIdx-1-popNum; //The index of the previous popOver item to hide
    if(hidePopIdx < 0){
        hidePopIdx = popOverLength-1-popNum
    }
    popsToHide.push(hidePopIdx%popOverLength);
  }
  popOverIdx+=numConcrPopOver;
  popOverIdx%=popOverLength;
  //Remove from popToHide array any items in the popToShow array.
  //This is done for the scenarios where the numebr of popovers to
  //Show in greater than half the total number of popovers, 
  //otherwise will hide immediatly after showing
  popsToHide = popsToHide.filter(function(itm) {return popsToShow.indexOf(itm) < 0;});
  popsToShow.forEach(function(itm){ //Iteratre of popOver items to show them
     $('.p'+itm).popover('show');
  });
  popsToHide.forEach(function(itm){ //Iteratre of popOver items to hide them
     $('.p'+itm).popover('hide');
  });
}, time);
});

您可以通过更改NUMCONCROPOVER变量来测试不同数量的同时弹出。我已经更新了您的JSFIDLE以包含新代码:

Wow!!!我喜欢。非常感谢你。我很快就会接受这个答案。Stackoverflow现在不允许!!
<div class="container">
  <a href="#" title="Header" class="myclass p0" data-toggle="popover" data-trigger="hover" data-placement="left" data-content="Some content">Hover Left</a> | 
  <a href="#" title="Header" class="myclass p1" data-toggle="popover" data-trigger="hover" data-placement="right" class="myclass" data-content="Some content">Hover Right</a> | 
  <a href="#" title="Header" class="myclass p2" data-toggle="popover" data-trigger="hover" data-placement="top" data-content="Some content Yo Bestie">Click Me</a> | 
  <a href="#" title="Header" class="myclass p3" data-toggle="popover" data-trigger="hover" data-placement="bottom" data-content="Some content Yo Bestie">Click Me</a>
</div>
0-1-2   ->   1-2-3   ->   2-3-0  ->  3-0-1  ...
$(document).ready(function(){
var time = 1000;
var popOverLength = $('.myclass').length;
var popOverIdx = 0;
var numConcrPopOver = 2;
var fun = setInterval(function(){
    var popsToShow = []; //Array that will hold index of popOvver items to show
  var popsToHide = []; //Array that will hold index of popOvver items to hide
  //Loop for the number of simultanious popOver you want to show
  for(var popNum=0; popNum<numConcrPopOver; popNum++){
    var currPopIdx = popOverIdx+popNum; //Index o fthe current  popOver to show
    popsToShow.push(currPopIdx%popOverLength); //Alwyas mod index to keep within lenght of popOver items
    var hidePopIdx = popOverIdx-1-popNum; //The index of the previous popOver item to hide
    if(hidePopIdx < 0){
        hidePopIdx = popOverLength-1-popNum
    }
    popsToHide.push(hidePopIdx%popOverLength);
  }
  popOverIdx+=numConcrPopOver;
  popOverIdx%=popOverLength;
  //Remove from popToHide array any items in the popToShow array.
  //This is done for the scenarios where the numebr of popovers to
  //Show in greater than half the total number of popovers, 
  //otherwise will hide immediatly after showing
  popsToHide = popsToHide.filter(function(itm) {return popsToShow.indexOf(itm) < 0;});
  popsToShow.forEach(function(itm){ //Iteratre of popOver items to show them
     $('.p'+itm).popover('show');
  });
  popsToHide.forEach(function(itm){ //Iteratre of popOver items to hide them
     $('.p'+itm).popover('hide');
  });
}, time);
});