10

我正在使用twitter bootstrap carcass进行 Web 项目开发。目前我有我为body标签设置的全屏背景图像,例如:

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

它看起来不错,当我尝试更改浏览器窗口大小时,调整大小效果很好。

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

我在这里找到了一个可能的解决方案,但让我感到困惑的是用于不同图像的 img 标签。我试图通过背景网址做同样的事情,但无法弄清楚。

4

2 回答 2

16

问题已解决。代码来源在这里。这比我想象的要容易:

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>
于 2013-10-19T22:10:10.087 回答
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;
}
于 2013-10-31T21:10:23.157 回答