引导手风琴没有扩大

时间:2019-10-04 13:50:39

标签: javascript jquery twitter-bootstrap

我正在尝试将手风琴用于setInterval事件和用户交互中。当用户单击一个部分时,setInterval应该停止更新可见部分。

因此,我有以下(我期望的)可重用代码:

// based on the id supplied, toggle the collapse function
function setSlideshow (cardId, autoClick=true) {
  if(!(autoClick)){
    //stop the counter
  }
  $('.slideshow img').removeClass('show')
  var clickedCard = $('.slideshow img#' + cardId)
  clickedCard.collapse('toggle')
}

// bind event for click with no userClick arg
$('#accordion .card button').click('click', slideShowClicked)

// function to call toggle
function nextSlide () {
  // search for id of next slide
  // i removed some code here for ease of reading
  var nextSlideId = $('#slideshow img.show + img').attr('id')
  // pass the false arg
  setSlideshow(nextSlideId, false)
}

// bind setinterval
function initSlideshow () {
  // add the automatic change event
  setInterval(function () {
      nextSlide()
  }, 1000)
}

问题是,当不手动单击(即不通过绑定事件,而通过setInterval方法传递)时,对于函数cardId具有完全相同的arg setSlideshow,则手风琴是未更新。

这是为什么?

(愿意在必要时发布标记)

0 个答案:

没有答案