Bootstrap carousel as website background

前端 未结 2 838
野趣味
野趣味 2020-12-14 12:31

I\'m using twitter bootstrap carcass for my web project development. Currently I have full screen background image which I set for the body tag like:

body {
         


        
相关标签:
2条回答
  • 2020-12-14 13:12

    Problem has been solved. Source of code is HERE. It's easier than I thought:

    HTML:

    <div id="myCarousel" class="carousel container slide">
    <div class="carousel-inner">
            <div class="active item one"></div>
            <div class="item two"></div>
            <div class="item three"></div>
    </div>
    </div>
    

    CSS:

    .carousel { z-index: -99; } /* keeps this behind all content */
    .carousel .item {
        position: fixed; 
        width: 100%; height: 100%;
        -webkit-transition: opacity 1s;
        -moz-transition: opacity 1s;
        -ms-transition: opacity 1s;
        -o-transition: opacity 1s;
        transition: opacity 1s;
    
    }
    .carousel .one {
        background: url(assets/img/slide3blur.jpg);
        background-size: cover;
        -moz-background-size: cover;
    }
    .carousel .two {
        background: url(assets/img/slide2blur.jpg);
        background-size: cover;
        -moz-background-size: cover;
    }
    .carousel .three {
        background: url(assets/img/slide1blur.jpg);
        background-size: cover;
        -moz-background-size: cover;
    }
    .carousel .active.left {
        left:0;
        opacity:0;
        z-index:2;
    }
    

    JS:

    <script type="text/javascript">
      $(document).ready(function() {
        $('.carousel').carousel({interval: 7000});
      });
    </script>
    
    0 讨论(0)
  • 2020-12-14 13:15

    I would add to mbigun's reply to use this css to keep the images from jerking:

    .carousel { z-index: -99; } /* keeps this behind all content */
    .carousel .item {
    position: fixed; 
     opacity: 0;
     left:0 !important;
    width: 100%; height: 100%;
    -webkit-transition: opacity 0.5s;
    -moz-transition: opacity 0.5s;
    -ms-transition: opacity 0.5s;
    -o-transition: opacity 0.5s;
    transition: opacity 0.5s;
    }
    .carousel .one {
    background: url(../images/layout/bgimages/homepage1.jpg);
    background-size: cover;
    -moz-background-size: cover;
    }
    .carousel .two {
    background: url(../images/layout/bgimages/homepage2.jpg);
    background-size: cover;
    -moz-background-size: cover;
    }
    .carousel .three {
    background: url(../images/layout/bgimages/homepage3.jpg);
    background-size: cover;
    -moz-background-size: cover;
    }
    
    .carousel .active {
    opacity: 1 !important;
    }
    
    .carousel .left {
    opacity: 1 !important;
    -webkit-transition: opacity 0.5s  !important;
    -moz-transition: opacity 0.5s  !important;
    -ms-transition: opacity 0.5s  !important;
    -o-transition: opacity 0.5s  !important;
    transition: opacity 0.5s  !important;
    }
    
    0 讨论(0)
提交回复
热议问题