1

我有这个功能(transComplete),它执行突出显示相关指示器的任务,向用户显示他们在哪个页面上,这些控制器/指示器的每个元素代表一个页面,并将适当地突出显示。

这可以独立工作,但是当我引入一个允许与指示器交互以在页面之间移动的单击功能时,它可以正确导航但不会根据需要突出显示(仅每两次单击有效),这使我相信这是我的代码中的逻辑问题。

真/假的布尔逻辑是原因,突出显示仅发生在变量“isOnSecond”的“真”情况下,所以我基本上需要一个解决方案,在单击时始终突出显示相关控制器

主要功能如下:

函数 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);
    }
4

1 回答 1

0

我认为当您仍在从一页迭代到下一页时,您制作了 trans 功能,现在用户可以转到任何帧,您需要每次清除任何突出显示,然后再次将其放在当前页面上。

或者更确切地说,为了性能起见,存储最后突出显示的,然后突出显示新的。

但是......为什么不直接放弃“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 的范围内)

于 2013-10-16T09:11:43.897 回答