我具有此函数(transComplete),该函数执行高亮显示相关指示器的任务,该指示器向用户显示用户所在的页面,这些控制器/指示器的每个元素代表一个页面,并将适当地突出显示。
但是,这是独立工作的,但是当我引入允许与指示器交互以在页面之间移动的单击功能时,它可以正确导航,但不能按需突出显示(仅两次单击即可工作),这使我相信它在我的代码中是一个逻辑问题。
原因是布尔值true / false,突出显示仅在变量“ isOnSecond”的“ true”情况下发生,因此我本质上需要一种始终在单击时突出显示相关控制器的解决方案
主要功能如下:
函数transComplete(){
slideTransStep = 0;
crtSlideIndex = nextSlideIndex;
// for IE filters, removing filters re-enables cleartype
if (nextSlide.style.removeAttribute) {
nextSlide.style.removeAttribute("filter");
// show next slide
showSlide((crtSlideIndex >= totalSlides) ? 1 : crtSlideIndex + 1);
//Highlights a nav circle every two transitions as the boolean alternates
if (isOnSecond == true) {
//unhighlight all controls
for (var i = 0; i < slidesControllersCollection.length; i++) {
if (slidesControllersCollection[i].className === slideHighlightClass) {
slidesControllersCollection[i].className = "";
}
// highlight the control for the next slide
document.getElementById("slide-control-" + crtSlideIndex).className = slideHighlightClass;
}
isOnSecond = false;
}
else {
isOnSecond = true;
}
}
onclick函数:
function clickSlide(control) {
showSlide(Number(control.id.substr(control.id.lastIndexOf("-")+1)),true);
}
我认为您是在仍要从一页迭代到下一页时进行转换的,现在用户可以移动任何帧,您每次都需要清除任何突出显示的内容,然后再次将其放在当前页面上。
或者,出于性能考虑,存储最后一个突出显示的内容,然后突出显示新的突出显示的内容。
但是……为什么不放弃“ onSecond”逻辑呢?对于用户而言,仅两次获得一次突出显示就没有多大意义了...
无论如何,如果您将其保留为onSecond想法,逻辑将是:
if (lastHighlighted) lastHighlighted.className = "";
if (isOnSecond) {
lastHighLighted = document.getElementById("slide-control-" + crtSlideIndex);
lastHighLighted.className = slideHighlightClass;
} else {
lastHighLighted = null;
}
isOnSecond = ! isOnSecond;
但是实际上我想知道您是否想要的不是没有onSecond逻辑的版本:
if (lastHighlighted) lastHighlighted.className = "";
lastHighLighted = document.getElementById("slide-control-" + crtSlideIndex);
lastHighLighted.className = slideHighlightClass;
(Rq将lastHighlighted声明为var,因此它可以在transComplete的范围内)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句