滑块内容被推出容器

时间:2014-05-09 00:29:28

标签: jquery html css

我在一些堆栈溢出用户的帮助下使用jquery成功创建了一个滑块,它运行得很好。但我想改变滑块的布局,不知何故打破了滑块,我不知道如何或为什么。基本上,我的所有幻灯片都被推出了容器,我认为这打破了jQuery。如果有人能帮我弄清楚我做了什么来打破我的代码,我会非常感激。

以下是工作版本:http://jsfiddle.net/videma/t534v/

以下是我的新代码无效的小提琴:http://jsfiddle.net/HfRdb/

这是代码:

HTML:

<div class="slideshow">


                            <div class="slideContainer">
                              <div class="slide">
                                <span class="slideMiddle"></span><img src="http://renegademagsu.com/wp-content/uploads/2014/05/malcolm-x.png">
                              </div>
                              <div class="slideInfo">
                                <p class="slideCaption">
                                  Denzel’s portrayal of Malcolm X was the role that most thought would win him an Oscar. In one scene, Malcolm and other members of the Nation of Islam demand the release of one of their fellow Muslims from jail by crowding the street outside of the building. After succeeding in this, Malcolm raises his hand and signals for his men to leave. With flick of his wrist, about one hundred protesters turn in unison and march away, as if a general had commanded them. Even a white cop notices his influence and says, “That’s too much power for a n***er to have.” If Malcolm X wasn’t bad ass enough, Denzel playing him just sweetened the deal.                                 </p>
                                <p class="slideCredit">
                                  <a href="http://www.popcornreel.com/jpgimg/x%20004.png" target="_blank">Popcorn Reel"                             </p>
                              </div> <!--slideInfo end-->
                              <div class="fix"></div>
                            </div> <!--slideContainer end-->
                           <!--end if each if-->


                            <div class="slideContainer">
                              <div class="slide">
                                <span class="slideMiddle"></span><img src="http://renegademagsu.com/wp-content/uploads/2014/05/remember-the-titans.png">
                              </div>
                              <div class="slideInfo">
                                <p class="slideCaption">
                                  No one can forget Denzel’s role as coach of a newly integrated high school football team in 1970s Virginia. Even though this is one of Denzel’s small bad ass roles, you have to admit, Coach Boone was scary enough to intimate anyone into doing 100 push ups.                              </p>
                                <p class="slideCredit">
                                  <a href="http://www.monologuedb.com/wp-content/uploads/2011/02/denzel-washington-coach-herman-boone-remember-the-titans.jpg" target="_blank">MonologueDB</a>                              </p>
                              </div> <!--slideInfo end-->
                              <div class="fix"></div>
                            </div> <!--slideContainer end-->
                           <!--end if each if-->


                            <div class="slideContainer">
                              <div class="slide">
                                <span class="slideMiddle"></span><img src="http://renegademagsu.com/wp-content/uploads/2014/05/safe-house.png">
                              </div>
                              <div class="slideInfo">
                                <p class="slideCaption">
                                  What do you do when you’re a fugitive and a CIA agent is looking after you?  Just follow Denzel’s bad ass steps in this one scene.  After Ryan Reynolds’ character has arrested Denzel’s character, he takes him to an arena where a soccer game is taking place in order to get weapons out of a locker. While in a crowd outside the arena, Denzel manages to trick the stadium security into believing he’s being kidnapped. They not only set him free, but then arrest Ryan Reyonlds. Denzel then effortlessly waltzes right out of the stadium. No sweat for a bad ass.                             </p>
                                <p class="slideCredit">
                                  <a href="http://www.hbo.com/movies/safe-house" target="_blank">HBO</a>                                </p>
                              </div> <!--slideInfo end-->
                              <div class="fix"></div>
                            </div> <!--slideContainer end-->
                           <!--end if each if-->


                            <div class="slideContainer">
                              <div class="slide">
                                <span class="slideMiddle"></span><img src="http://renegademagsu.com/wp-content/uploads/2014/05/training-day.png">
                              </div>
                              <div class="slideInfo">
                                <p class="slideCaption">
                                  Who could forget Denzel’s Academy Award winning role as Detective Alonzo Harris, the corrupt and rogue narcotics officer who plays by his own rules.  A memorable scene is when Alonzo and the rookie cop Jake, stop two guys from raping a 14-year-old girl. While Jake chooses to arrest them, Alonzo grabs one of the men, puts a knife to his throat, and then points 2 guns at his crouch, threatening to shoot him.  Instead of shooting he punches him and says, “Man I’m thirsty, I could use a beer.”                                </p>
                                <p class="slideCredit">
                                  <a href="http://roley.tumblr.com/post/8472254874/told-me-to-suck-your-dick-is-that-what-you" target="_blank">roley.tumblr.com                             </p>
                              </div> <!--slideInfo end-->
                              <div class="fix"></div>
                            </div> <!--slideContainer end-->
                           <!--end if each if-->


                            <div class="slideContainer">
                              <div class="slide">
                                <span class="slideMiddle"></span><img src="http://renegademagsu.com/wp-content/uploads/2014/05/man-on-fire.png">
                              </div>
                              <div class="slideInfo">
                                <p class="slideCaption">
                                  If you want to learn about revenge, just watch Denzel in action in this movie after kidnappers try to take little Dakota Fanning. Denzel, her bodyguard, gets ahold of a corrupt cop who he needs answers from, and interrogates him by sticking a detonator up his rectum, threatening to blow the cop up if he doesn’t get information. However, when he finally gets the answers he’s looking for, Denzel detonates the bomb anyway and walks away from the explosion in slow motion. Total bad ass move.                              </p>
                                <p class="slideCredit">
                                  <a href="http://www.thefancarpet.com/uploaded_assets/images/gallery/1498/Man_On_Fire_18347_Medium.jpg" target="_blank">The Fan Carpet</a>                             </p>
                              </div> <!--slideInfo end-->
                              <div class="fix"></div>
                            </div> <!--slideContainer end-->
                           <!--end if each if-->


                            <div class="slideContainer">
                              <div class="slide">
                                <span class="slideMiddle"></span><img src="http://renegademagsu.com/wp-content/uploads/2014/05/american-gangster.png">
                              </div>
                              <div class="slideInfo">
                                <p class="slideCaption">
                                  Denzel plays the notorious gangster, Frank Lucas, who kills a man who doesn’t pay him the money he owes.  Without hesitation, Lucas kills the man in the street in broad daylight with people around. As if that wasn’t badass enough, right after, he returns to the restaurant he’d been in, and continues eating his food, as if nothing had happened.  Now that’s bad ass.                                </p>
                                <p class="slideCredit">
                                  <a href="http://www.dvdbeaver.com/film2/DVDReviews42/american%20gangster%20blu-ray/HF7Y9005_american_gangster_blu-ray.jpg" target="_blank">DVD Beaver</a>                             </p>
                              </div> <!--slideInfo end-->
                              <div class="fix"></div>
                            </div> <!--slideContainer end-->
                           <!--end if each if-->
                         <!--end each-->
                    </div><!--slideshow end-->
                    <div class="slideNav">
                        <div class="prevSlide">
                          <i class="fa fa-chevron-left fa-2x"></i>
                        </div>
                        <div class="slideCount"></div>
                        <div class="nextSlide">
                          <i class="fa fa-chevron-right fa-2x"></i>
                        </div>
                        <div class="fix"></div>
                    </div>
                 <!--end if-->
              </div>
            </div>

CSS:

.slideshow {
    background-color: #FFFFFF;
    width: 100%;
    height: 520px;
    position: relative;
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    }

.slideContainer {
  background-color: #FFFFFF;
    padding: 10px;
    width: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    }

.slide {
    width: 100%;
    height: 500px;
    text-align: center;
    border: 1px solid #000;
    }

.slideMiddle {
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}

.slide img {
    max-width: 100%;
    max-height: 100%;
    vertical-align: middle;
  border: 1px solid #000;
    }

.slideInfo {
    color: #FFF;
    width: 100%;
    height: 80%;
    padding: 10px;
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    }

.slideCredit {
    width: 100%;
    font-style: italic;
    font-size: 12px;
    }


.slideNav {
    width: 100%;
    padding: 10px;
    color: #000;
    position:relative;
    border: 1px solid #000;
}
.prevSlide {
    width: 33.3%;
    float: left;
}
.nextSlide {
    width: 33.3%;
    float: right;
text-align: right;
}
.slideCount {
    width: 23.3%;
    text-align: center;
    position:absolute;
    left:40%;
}

jQuery的:

$('.slideCount').each(function(){
        var text='1/'+$(this).parents('div.postContainer').find('.slideContainer').length
        $(this).text(text)
        })

    $('.nextSlide').show()  
    $('.prevSlide').hide()

    $('div.nextSlide').click(function (e){
        var count=parseInt($(this).siblings('.slideCount').text())
        var slideshow=$(this).parents('div.postContainer').find('.slideshow')
        var slides = $(slideshow).children().length;
        if(count===slides){
            e.preventDefault()
            }else{
            count++
            $(this).parents('div.postContainer').find('div.slideContainer:first').appendTo(slideshow) 
            $(this).siblings('.slideCount').text(count+'/'+slides)
        }
        if(count===slides){$(this).hide()}else{$(this).parent().find('div.prevSlide').show()}
    });

    $('.prevSlide').click(function (e){
        var count=parseInt($(this).siblings('.slideCount').text().slice(0,-2))
        var slideshow=$(this).parents('div.postContainer').find('.slideshow')
        var slides = $(slideshow).children().length;
        if(count===1){e.preventDefault()}else{
            count--
            $(this).parents('div.postContainer').find('div.slideContainer:last').prependTo(slideshow) 
            $(this).siblings('.slideCount').text(count+'/'+slides)
        } 
        if(count===1){$(this).hide()}else{$(this).parent().find('div.nextSlide').show()} 
    });

1 个答案:

答案 0 :(得分:0)

.slideNav div的填充为10px,宽度为100%。这将把容器外的div推到10 + 10 = 20px。也可以使用box-sizing:border-box

由于您没有正确关闭标签,因此还存在dom错误。解决这个问题。