javascript - 将我的 'flipping' 圆圈定位在页面中间

标签 javascript jquery html css

我创建了一个包含内容的圆圈,它不仅可以翻转而且可以悬浮...我想确保这个圆圈位于用户浏览器的中间,出于某种原因(我相信这是由于flip) 圆没有居中。

jsFiddle

HTML

<div class="flip-container">
                <div class="flipper">
                    <div class="front">
                        <div class="circle floating">
                            <img src="http://mogul.london/images/logo-home.png" width="217" height="107">
                            <span class="title">Title</span>
                            <span class="subline">Subtitle here</span>
                        </div>
                    </div>
                    <div class="back">
                        <div class="circle floating">
                            <span class="calltext">Call us now on</span>
                            <span class="number">000 000 0000</span>
                            <span class="ordertext">to order or make a reservation</span>
                        </div>
                    </div>
                </div>
            </div>

CSS

body {
    font-family: "Trebuchet MS", Helvetica, sans-serif;
    font-size: 15px;
    color:#fff;
}

.flip-container {
    perspective: 1000;
    cursor: pointer;
    position: absolute;
    top: 50%;
    left:50%;
    transform: translateX(-50%) translateY(-50%);
}
    /* flip the pane when hovered */
    .flip-container:hover .flipper, .flip-container.hover .flipper {
        transform: rotateY(180deg);
    }

.flip-container, .front, .back {
    width: 320px;
    height: 480px;
}

/* flip speed goes here */
.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;

    position: relative;
}

/* hide back of pane during swap */
.front, .back {
    backface-visibility: hidden;

    position: absolute;
    top: 0;
    left: 0;
}

/* front pane, placed above back */
.front {
    z-index: 2;
    transform: rotateY(0deg); /* for firefox 31 */
}

/* back, initially hidden pane */
.back {
    transform: rotateY(180deg);
}

.circle {
    background: rgba(255, 0, 73, 0.67);
    text-align: center;
    padding: 85px 35px;
    display: inline-block;

    height: 200px;
    width: 300px;
    -webkit-border-radius: 200px;
    -moz-border-radius: 200px;
    border-radius: 200px;
}

.circle span {
    display: block;
    text-transform: uppercase;
}

.circle span.title {
    font-size: 60px;
    font-weight: bold;
    letter-spacing: -2px;
}
.circle span.subline {
    font-size: 18px;
    margin-top: -5px;
}
.circle span.calltext {
    font-size: 35px;
    margin-top: 30px;
}

.circle span.number {
    letter-spacing: -2px;
    font-size: 46px;
    font-weight: bold;
}

.circle span.ordertext {
    font-size: 18px;
}

.floating{
    float: left;
    -webkit-animation-name: Floatingx;
    -webkit-animation-duration: 3s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: ease-in-out;
    -moz-animation-name: Floating;
    -moz-animation-duration: 3s;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: ease-in-out;
    margin-left: 30px;
    margin-top: 5px;
}

@-webkit-keyframes Floatingx{
    from {-webkit-transform:translate(0, 0px);}
    65% {-webkit-transform:translate(0, 15px);}
    to {-webkit-transform: translate(0, -0px);    }    
}

@-moz-keyframes Floating{
    from {-moz-transform:translate(0, 0px);}
    65% {-moz-transform:translate(0, 15px);}
    to {-moz-transform: translate(0, -0px);}    
}

最佳答案

你错误地计算了.flip-container的宽度和高度:

.flip-container, .front, .back {
    width: 370px; // .circle height + 2*padding = 300 + 2*35
    height: 385px; // .circle width + 2*padding + animation translate = 200 + 2*85 + 15
}

Fiddle (此外,我删除了 .floating 中的边距)

关于javascript - 将我的 'flipping' 圆圈定位在页面中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26186018/

相关文章:

javascript - 是否有任何 Ruby 工具或 JavaScript 库来验证 html 格式是否良好?

javascript - 隐藏然后专注于下面的选择元素

html - 如何使用html和css绘制SVG图标?

javascript - Google Maps API,是否可以突出显示特定街道?

javascript - ajax 调用上的 GET 参数(进入模式对话框)

javascript - TypeError : Object. 条目不是 MERN-CLI 安装中的功能

javascript - 固定菜单栏不适用于 chrome 和 firefox

javascript - JQuery:fadeIn() 不适用于 appendTo()

javascript - AJAX 和相对路径范围

php - 如何让 <table> 居中?