如何淡出循环背景图像在Twitter的Bootstrap 3 [英] How to fade loop background images in Twitter's Bootstrap 3

查看:200
本文介绍了如何淡出循环背景图像在Twitter的Bootstrap 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Twitter的Bootstrap Framework(版本3)制作了一个网站,我想使用 Roko C. Buljan 请参阅StackOverflow的帖子:如何淡出循环背景图片?

I'm making a website with Twitter's Bootstrap Framework (version 3), and I want to use the awesome script made by Roko C. Buljan Please see this StackOverflow post: How to fade loop background images?

这是我的代码:

HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="img/favicon.ico">
        <title>MY SITE</title>
        <!-- Bootstrap core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <!-- Custom styles for this template -->
        <link href="css/starter-template.css" rel="stylesheet">
        <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
        <!--[if lt IE 9]><script src="js/ie8-responsive-file-warning.js"></script><![endif]-->
        <script src="js/ie-emulation-modes-warning.js"></script>
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
            <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <nav class="navbar navbar-default navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" rel="home" title="PAGE">
                        <img style="max-width:64px; margin-top: -8px;" src='img/logo.png'>
                    </a>
                </div>
                <div id="navbar" class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="#info"><i class='glyphicon glyphicon-tasks'></i> Info</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="logout.php"><i class='glyphicon glyphicon-lock'></i> Logout</a></li>
                    </ul>
                </div><!--/.nav-collapse -->
            </div>
        </nav>
        <div class="fakebg"></div>
        <div id='page' class="container">
            <div class="starter-template">
                <div class="row">
                    ...
                </div><!-- row -->
            </div><!-- starter template -->
        </div><!-- /.container -->
        <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script src="js/jquery.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/bgchanger.js"></script>
    </body>
</html>

CSS:

html, body, .fakebg
{
    background: #000 none 0 50% / no-repeat center center fixed;
    overflow:auto !important;
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover;
}
#page
{
    overflow:auto !important;
}
.fakebg
{
    overflow:auto !important;
    position:absolute;
    top:0;
    bottom:0;
    left:0;
    right:0;
    width:100%;
    height:100%;
    background: #000 none 50% / cover no-repeat;
}

bgchanger.js 是Roko的脚本。

问题:我的页面很长(高度),所以背景在一定高度处截断。

The problem: My page is long (height), so the background cuts off at a certain height. This happens when I scroll.

我做错了什么?

推荐答案

p>好了,你需要设置

Well, turns out that you need to set

html, body{ height:100%;}

,以允许 .fakebg (html / body parent)。

in order to allow the .fakebg enlarge it's size to 100% (of the html / body parent ).

这篇关于如何淡出循环背景图像在Twitter的Bootstrap 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆