如何使这种加载叠加效果响应?

时间:2013-11-14 16:10:56

标签: css css3 overlay css-transitions font-awesome

我正在尝试使用中间的旋转图标进行加载叠加效果。我使用fontawesome。 所以我对此进行了编码: http://jsfiddle.net/eys3d/7/

它有效,但我正在尝试使其响应。我的意思是,当截面尺寸减小时,旋转尺寸也会减小(保持居中)。如果部分的大小增加,则为对位。

我尝试使用em单位,但我没有得到预期的结果。

这是最好的方法吗?我如何才能使其响应?

CSS

section {
    width: 200px;
    height: 200px;
    margin: 50px;
}
#overlay {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 99999999999;
    background: rgba(0, 0, 0, 0.5);
}
#overlay i {
    position: absolute;
    top: 50%;
    left: 50%;
}
.spin-big {
    font-size: 50px;
    height: 50px;
    width: 50px;
    margin-top: -25px;
    margin-left: -25px;
}
.spin-normal {
    font-size: 35px;
    height: 35px;
    width: 35px;
    margin-top: -22.5px;
    margin-left: -22.5px;
}
.spin-small {
    font-size: 20px;
    height: 20px;
    width: 20px;
    margin-top: -10px;
    margin-left: -10px;
}

HTML

<section>
    <div id="overlay"> 
        <i class="fa fa-spinner fa-spin spin-big"></i>
    </div>
</section>

<section>
    <div id="overlay"> 
        <i class="fa fa-spinner fa-spin spin-normal"></i>
    </div>
</section>

<section>
    <div id="overlay"> 
        <i class="fa fa-spinner fa-spin spin-small"></i>
    </div>
</section>

任何提示,建议或帮助将不胜感激,如果您需要更多信息,请告诉我,我将编辑该帖子。

4 个答案:

答案 0 :(得分:5)

为什么你不会尝试将display:table属性用于叠加div,display:table-cell用于fontawesome i类?如下:

#overlay {
    width: 100%;
    height: 100%;
    display:table;
    background: rgba(0, 0, 0, 0.5);
}
#overlay i {
   display:table-cell;
    vertical-align:middle;
    text-align:center;
}

工作Demo

答案 1 :(得分:1)

你可以使用它以获得良好的效果

.loading 
{
 pointer-events: all;
 z-index: 99999;
 border: none;
 margin: 0px;
 padding: 0px;
 width: 100%;
 height: 100%;
 top: 0px;
 left: 0px;
 cursor: wait;
 position: fixed;
 background-color: rgba(0, 0, 0, 0.6);
}

答案 2 :(得分:0)

试着寻找类似的解决方案。

响应性地改变字体大小的唯一方法是通过媒体查询。

即:

@media min-device-width: 300px{
    font-size: 8px;
}

@media min-device-width: 480px{
    font-size: 12px;
}

分机..

答案 3 :(得分:0)

-----------div in Layout Page---------------
 <div class="loading-bg" id="dvSpinner">
        <img src="~/Areas/Images/loader.gif">
    </div>
----------css-----------
.loading-bg {
    background: #e9e9e9;
    display: none;
    height: 100%;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    opacity: 0.5;
    z-index: 5000;
    width: 100%;
}
.loading-bg img{
    position: absolute;
    top: 42%;
    left: 46%;
    height: 100px;
    width: 100px;
}


-------------html------------
<div class="appendInputFieldForUAIHiddenDiv"
                     id="appendInputFieldForUAIHiddenDiv">

                    @Html.TextBoxFor(model => model.PrimaryEmail, new { @class = "form-control enter-email-FPHidden-div", id = "email-address-entered", name = "email-address-entered" })
                    @Html.ValidationMessageFor(model => model.PrimaryEmail)

                    <button type="submit" class="btn btn-info submit-button-FPHidden" onclick="submitbuttonFPHidden()">
                        @ASRP.Resources.Resource.Submit
                    </button>
                </div>

--------------scripts--------------------------

function submitbuttonFPHidden() {


    var username = $('#email-address-entered').val();
    if (username == null || username == "") {
        document.getElementById("email-address-entered").style.borderColor = "#ff0232";
        return false;
    }

    if (!validateEmail(username)) {
        document.getElementById("email-address-entered").style.borderColor = "#ff0232";
        return false;
    }
    document.getElementById('dvSpinner').style.display = "block";
    $.ajax({
        url: "../User/ForgotPassword",
        data: { email: username },
        dataType: "json",
        type: "post",
        error: function (error, msg) {
            $('div#dvSpinner').hide();
            return false;
        },
        success: function (data) {
            if (data.success) {


                if (data.emailSent == "Successful") {
                    document.getElementById('FPHiddenDivContainer').style.display = "none";
                    document.getElementById('entered-email-address').style.display = "block";
                    document.getElementById('entered-email-address-para').innerHTML = document.getElementById('email-address-entered').value;
                    document.getElementById('PwdMsgNew').style.display = "none";

                }
                else if (data.emailSent == "Failure")
                {
                    document.getElementById('FPHiddenDivContainer').style.display = "none";
                    document.getElementById('entered-email-address').style.display = "block";
                    document.getElementById('entered-email-address-para').innerHTML = document.getElementById('email-address-entered').value;
                    document.getElementById('PwdMsg').style.display = "none";
                    document.getElementById('lblThankYou').style.display = "none";

                }


            }
            else {
                var ddlLangValue = $('#ddlLangs').val();
                setCookie("culture", ddlLangValue, 31536e3);
                var resources = {}; // Global variable.

                (function ($) {

                    $.getJSON("Resource/GetResources", function (data) {
                        resources = data;
                        alert(resources.fpUnabletoProcessReq);
                    });
                })(jQuery);
            }
            document.getElementById('dvSpinner').style.display = "none";
        }

    });
    return true;
}