简体   繁体   English

JavaScript Switch语句使不透明度消失为无,但不会消失

[英]JavaScript Switch Statement Fades Opacity to None But Doesn't Fade it Back

I have a really weird situation. 我的情况真奇怪。 The idea is there is a scroller that moves from left to right to display different groups. 这个想法是有一个滚动器,它从左到右移动以显示不同的组。 But when it stops to show specific group, there are links to leaf through different "pages" of the group. 但是,当停止显示特定组时,存在通过该组的不同“页面”指向叶子的链接。 Now in order to do this, you click link one page fades and another fades in. Everything worked smooth until I apparently did something to agitate things and I'm not sure what it is. 现在,要执行此操作,请单击链接,淡入淡出一页,然后淡入淡出。一切工作都进行得很顺利,直到我显然做出了一些激动人心的事情,并且不确定是什么。 But the problem is I can fade in and out the first page of the group fine. 但是问题是我可以淡入和淡出小组的第一页。 But when I try to fade in and out the second or third, although the paragraph text DOES fade in and out, the image DOES NOT. 但是,当我尝试淡入和淡出第二个或第三个时,尽管段落文本确实淡入和淡出,但是图像却没有。 And if you look at the switch statement, it appears that the image should behave the same as the text: 并且,如果您查看switch语句,则图像的行为应与文本相同:

     $(".slidernav a").click(function(){
  // var original = $(".slidernav a:first");
  var current = $(this).attr("href");

  switch(current) {
   case "#first":
    $("#group1 img").animate({
           opacity: 0
       }, 500 );
    $("#group1 p").animate({
           opacity: 0
       }, 500 );     
    $("#group1 .1").animate({
           opacity: 1
       }, 500 );
    $("#group1 p.first").animate({
           opacity: 1
       }, 500 );      
    break;

   case "#second":
    $("#group1 img").animate({
           opacity: 0
       }, 500 );
    $("#group1 p").animate({
           opacity: 0
       }, 500 );   
    $("#group1 .2").animate({
           opacity: 1
       }, 500 );
    $("#group1 p.second").animate({
           opacity: 1
       }, 500 );
    break;

   case "#third":
    $("#group1 img").animate({
           opacity: 0
       }, 500 );
    $("#group1 p").animate({
           opacity: 0
       }, 500 );
    $("#group1 .3").animate({
           opacity: 1
       }, 500 );
    $("#group1 p.third").animate({
           opacity: 1
       }, 500 );
    break;
  }
 });
   });

markup: 标记:

            <div class="main_view">
            <div class="window">
                <div class="image_reel">
           <div id="group1">
                     <a href="#"><img src="images/reel_1.png" class="1" /></a>
            <a href="#"><img src="images/reel_1b.png" class="2" /></a>
            <a href="#"><img src="images/reel_1c.png" class="3" /></a>

            <p class="first"> Claim A</p>
            <p class="second"> Claim B</p>
            <p class="third"> Claim C</p>

            <div class="slidernav">
             <a href="#first"> Claim A</a> 
             <a href="#second"> Claim B</a> 
             <a href="#third"> Claim C</a> 
            </div>
           </div>

           <div id="group2">
                     <a href="#"><img src="images/reel_2.png" /></a>
            <a href="#"><img src="images/reel_2b.png"  /></a>
            <a href="#"><img src="images/reel_2c.png" /></a>

            <p class="first"> Claim A</p>
            <p class="second"> Claim B</p>
            <p class="third"> Claim C</p> 

            <div class="slidernav">
             <a href="#first"> Claim A</a> 
             <a href="#second"> Claim B</a> 
             <a href="#third"> Claim C</a> 
            </div>          
           </div>

           <div id="group3">
                     <a href="#"><img src="images/reel_3.png" alt="" /></a>
            <a href="#" id="sixth"><img src="images/reel_1b.png" /></a>
            <a href="#" id="seventh"><img src="images/reel_1b.png" /></a>
           </div>

           <div id="group4">
                     <a href="#"><img src="images/reel_4.png" alt="" /></a>
            <a href="#" id="eigth"><img src="images/reel_1b.png" /></a>
            <a href="#" id="ninth"><img src="images/reel_1b.png" /></a>
           </div>


                </div>


            </div>
            <div class="paging">
                <a href="#" rel="1">1</a>
                <a href="#" rel="2">2</a>
                <a href="#" rel="3">3</a>
                <a href="#" rel="4">4</a>
            </div>

css: CSS:

.window {
  margin-top: 20px;
  height:286px; width: 655px;
  overflow: hidden; /*--Hides anything outside of the set width/height--*/ 
/* THIS IS WHAT MAKES IT WORK - THE TEXT MUST BE SITTING NEXT TO OTHER TEXT */
  position: relative;
}
.image_reel {
  position: absolute;
  top: 0; left: 0;
}
.image_reel div {position: relative; width: 655px; float: left;} 

.image_reel img.1 {position: absolute; top: 0; left: 0; z-index: 3;}
.image_reel img.2 {position: absolute; top: 0; left: 0; z-index: 2;}
.image_reel img.3 {position: absolute; top: 0; left: 0; z-index: 1;}

.image_reel p.first {position: absolute; top: 0; left: 0; z-index: 3;}
.image_reel p.second {position: absolute; top: 0; left: 0; z-index: 2;}
.image_reel p.third {position: absolute; top: 0; left: 0; z-index: 1;}

.image_reel div.slidernav {position: absolute; top: 200px; left: 0px; z-index: 4;}
.image_reel div.slidernav a {display: block; color: #fff;} 

Thanks for any response. 感谢您的任何回复。

It looks like your class names are missing, syntactically incorrect, or logically wrong. 您的类名似乎丢失,语法错误或逻辑错误。

  • The images in group 1 have classes, but those in group 2 and group 3 do not. 组1中的图像具有类别,而组2和组3中的图像则没有。
  • Class names can't start with numbers. 类名不能以数字开头。 You have 1 , 2 and 3 as classes. 你有123为类。
  • In every case , your selector starts with #group1 . 在每种case ,您的选择器都以#group1开头。 You never select the other groups. 您永远不会选择其他组。 Is that your intent? 那是你的意图吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM