Bootstrap转盘作为网站背景

时间:2013-10-19 18:46:50

标签: css3 twitter-bootstrap background-image carousel

我正在使用twitter bootstrap carcass进行网站项目开发。 目前我有全屏幕背景图像,我为身体标签设置如下:

body {
  background: url('Content/images/planet.gif') no-repeat center center fixed;
  -webkit-background-size: cover; 
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

看起来不错,当我尝试更改浏览器窗口大小时,调整大小非常有效。

现在我想通过添加背景轮播为我的网站添加一些视觉效果。有没有办法在整个背景下实现标准的bootstrap轮播?

我找到了一个可能的解决方案HERE,但令我感到困惑的是img标签,它们用于不同的图像。我试图通过背景网址做同样的事情,但无法弄明白。

2 个答案:

答案 0 :(得分:14)

问题已经解决了。代码来源是HERE。这比我想象的容易:

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>

答案 1 :(得分:2)

我会添加到mbigun的回复中使用这个css来防止图像抖动:

.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;
}