javascript - How do i add a Bootstrap carousel to Ruby on rails app? -
i new developer , trying add bootstrap carousel rails app.
this carousel trying add in particular: http://arturssmirnovs.com/blog/bootstrap-carousel-100-height-and-width/
so far i've gotten white left , right pointers show carousel (ex: navigation pointers < >)
here's html code, snabbed link above, inserted portion in about.html.erb page, static page want carousel appear in
views/layouts/staticpages/about.html.erb:
<div class="aboutslide"> <div id="mycarousel" class="carousel slide" data-ride="carousel"> <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> <div class="carousel-inner"> <div class="item bg bg1 active"> <div class="container"> <div class="carousel-caption"> <h1>example headline.</h1> <p>note: if you're viewing page via <code>file://</code> url, "next" , "previous" glyphicon buttons on left , right might not load/display due web browser security rules.</p> <p><a class="btn btn-lg btn-primary" href="#" role="button">sign today</a></p> </div> </div> </div> <div class="item bg bg2"> <div class="container"> <div class="carousel-caption"> <h1>another example headline.</h1> <p>cras justo odio, dapibus ac facilisis in, egestas eget quam. donec id elit non mi porta gravida @ eget metus. nullam id dolor id nibh ultricies vehicula ut id elit.</p> <p><a class="btn btn-lg btn-primary" href="#" role="button">learn more</a></p> </div> </div> </div> <div class="item bg bg1"> <div class="container"> <div class="carousel-caption"> <h1>one more measure.</h1> <p>cras justo odio, dapibus ac facilisis in, egestas eget quam. donec id elit non mi porta gravida @ eget metus. nullam id dolor id nibh ultricies vehicula ut id elit.</p> <p><a class="btn btn-lg btn-primary" href="#" role="button">browse gallery</a></p> </div> </div> </div> </div> <a class="left carousel-control" href="#mycarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a> <a class="right carousel-control" href="#mycarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a> </div> </div>
here app/assets/stylesheets/carousel.css
file:
html, body { height:100%; margin:0; padding:0; } .carousel, .item, .active { height:100%; } .carousel-inner { height:100%; } .carousel { margin-bottom: 60px; } .carousel-caption { z-index: 10; } .carousel .item { background-color: #777; } .carousel .carousel-inner .bg { background-repeat:no-repeat; background-size:cover; } .carousel .carousel-inner .bg1 { background-image:url(bg1.jpg); background-position: center top; } .carousel .carousel-inner .bg2 { background-image:url(bg2.jpg); background-position: center center; } .carousel .carousel-inner .bg3 { background-image:url(bg3.jpg); background-position: center bottom; } @media (min-width: 768px) { /* bump size of carousel content */ .carousel-caption p { margin-bottom: 20px; font-size: 21px; line-height: 1.4; } }
and there docs.js file have inserted in apps/assets/javascripts/docs.js
. can't post because file big.
the issue button images need add images app/assets/images
directory , change css use rails asset_path helper:
.carousel .carousel-inner .bg { background-repeat:no-repeat; background-size:cover; } .carousel .carousel-inner .bg1 { background-image:url(<%= assets_path 'bg1.jpg' %>); background-position: center top; } .carousel .carousel-inner .bg2 { background-image:url(<%= assets_path 'bg2.jpg' %>); background-position: center center; } .carousel .carousel-inner .bg3 { background-image:url(<%= assets_path 'bg3.jpg' %>); background-position: center bottom; }
this uses erb (embedded ruby) add correct url in stylesheet. can change extension of file '.css.scss' , use sass-rails
helpers.
.carousel.carousel-inner { .bg { background-repeat:no-repeat; background-size:cover; } .bg1 { background-image:url( image-url('bg1.jpg') ); background-position: center top; } .bg2 { background-image:url( image-url('bg2.jpg') ); background-position: center center; } .bg3 { background-image:url( image-url('bg3.jpg') ); background-position: center bottom; } }
Comments
Post a Comment