简体   繁体   English

如何制作具有简单视差效果的自举轮播?

[英]How to make a bootstrap carousel with simple parallax effect?

i'm using the bootstrap carousel. 我正在使用自举轮播。 Now it works well (as presented on the bootstrap website) 现在可以正常使用了(如引导网站上所述)

What I want to do is to make whole slider (including images, buttons, captions..) positions : fixed to give a simple parallax effect when scrolling down. 我要做的是使整个滑块(包括图像,按钮,标题..)位置: fixed为在向下滚动时提供简单的视差效果。

This is an example in jsfiddle 这是jsfiddle中的一个例子

 $(function () { $('#homeCarousel').carousel({ interval:2000, pause: "false" }); $('#playButton').click(function () { $('#homeCarousel').carousel('cycle'); }); $('#pauseButton').click(function () { $('#homeCarousel').carousel('pause'); }); }); 
 #carouselButtons { margin-left: 100px; position: absolute; bottom: 0px; } .next_section{ width : 100%; height: 500px; position:relative; background-color: blue; z-index:100; } p{color: #FFF;} .item{ position:fixed; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <!-- Carousel --> <div id="homeCarousel" class="carousel slide"> <!-- Menu --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- Items --> <div class="carousel-inner"> <!-- Item 1 --> <div class="item active"> <img src="http://lorempixel.com/1500/600/abstract/1"/> <div class="container"> <div class="carousel-caption"> <h1>Bootstrap 3 Carousel Layout</h1> <p>This is an example layout with carousel that uses the Bootstrap 3 styles.</p> <p><a class="btn btn-lg btn-primary" href="http://getbootstrap.com">Learn More</a> </p></div> </div> </div> <!-- Item 2 --> <div class="item"> <img src="http://lorempixel.com/1500/600/abstract/2"/> <div class="container"> <div class="carousel-caption"> <h1>Changes to the Grid</h1> <p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p> <p><a class="btn btn-large btn-primary" href="#">Learn more</a></p> </div> </div> </div> <!-- Item 3 --> <div class="item"> <img src="http://lorempixel.com/1500/600/abstract/3" /> <div class="container"> <div class="carousel-caption"> <h1>Percentage-based sizing</h1> <p>With "mobile-first" there is now only one percentage-based grid.</p> <p><a class="btn btn-large btn-primary" href="#">Browse gallery</a></p> </div> </div> </div> </div> <!-- Controls --> <a class="left carousel-control" href="#myCarousel" data-slide="prev"> <span class="icon-prev"></span> </a> <a class="right carousel-control" href="#myCarousel" data-slide="next"> <span class="icon-next"></span> </a> <div id="carouselButtons"> <button id="playButton" type="button" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-play"></span> </button> <button id="pauseButton" type="button" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-pause"></span> </button> </div> </div> <div class = "next_section"> <p> i want the slider to go under this blue area when scroll down, the blue wrapper needs to cover the whole slider ! <br> the carousel-caption needs to be centered on the slider too and don't "move" ! </p> </div> 

Please any help ? 请任何帮助?

i have solved usig a background-img instead of img tag, ad i have applied the backgroud-attachmet:fixed 我已经解决了usig一个background-img而不是img标签,并且我已经应用了backgroud-attachmet:fixed

<div class="carousel-inner" role="listbox">
          <div class="item  active slideimg1">
                <div class="carousel-caption">
                    <h1>Lorem ipsus</h1>
                    <p>Etiam tellus felis, fringilla vitae dictum id, dapibus id est.</p>
                </div>
          </div>
 </div>

css: CSS:

.slideimg1{background-image:......;}

.carousel-inner .item
{
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;

    -webkit-background-position: center;
    -moz-background-position: center;
    -o-background-position: center;
    background-position: center;

    -webkit-background-attachment: fixed;
    -moz-background-attachment: fixed;
    -o-background-attachment: fixed;
    background-attachment: fixed;
}

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

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