首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery .effect()破坏网页样式

jQuery .effect()破坏网页样式
EN

Stack Overflow用户
提问于 2015-07-24 02:15:18
回答 1查看 28关注 0票数 0

我是一个初学者,试图在小项目的实践中工作。我一直在为我的儿子做一个小游戏,我的jQuery .effect()动画有一个小问题。当正确的div被点击时,它有.effect('bounce')动画,但是它破坏了div在页面上的位置。这是游戏的链接。我怎么才能阻止这一切的发生呢?我假设在我的CSS中进行编辑。

对不起,如果我没有迅速回应,我是张贴在我睡觉前(尝试解决这一整晚),谢谢提前!

代码语言:javascript
复制
$(document).ready(function() {
    $('.wrong').click(function() {
        $(this).effect('explode');
    });
    
    $('.right').click(function() {
        $(this).effect('bounce', {times:3}, 500);
        $('#level1').delay(700).slideUp('slow');
        $('#level2').delay(710).slideDown('slow');
    });
});
代码语言:javascript
复制
html {
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
    text-align:center;
    height: 100%;
}

#level1 {
    position: relative;
    background-color: lightgrey;
    height: 100%;
    margin: 0;
    padding: 0;    
}

#level2 {
    height: 100%;
    display: none;
    margin: 0;
    padding: 0;
}

.inner-container {
    position: relative;
    height: 100%;
}

.question {
    text-align: center;
    font-size: 20px;
    padding-top: 5%;
    margin: 0;
}

.circles {
    text-align: center;
    margin-top: 10%;
}

.red {
    display: inline-block;
    height: 100px;
    width: 100px;
    border-radius: 100%;
    background-color: red;
    margin: 0 5%;
}

.blue {
    display: inline-block;
    height: 100px;
    width: 100px;
    border-radius: 100%;
    background-color: blue;
    margin: 0 5%;
}

.green {
    display: inline-block;
    height: 100px;
    width: 100px;
    border-radius: 100%;
    background-color: green;
    margin: 0 5%;
}
代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="css/jquery-ui.min.css">
        <link rel="stylesheet" href="css/custom.css">
        <title>Color Game</title>
    </head>
    <body>
        <div id="level1">
            <div class="inner-container">
                <p class="question">Which color is <span style="color: blue">BLUE</span></p>
                <div class="circles">
                    <div class="red wrong"></div>
                    <div class="blue right"></div>
                    <div class="green wrong"></div>
                </div>
            </div>
        </div>
        <div id="level2">
            <div class="inner-container">
                <p class="question">Which color is <span style="color: green">GREEN</span></p>
                <div class="circles">
                    <div class="blue wrong"></div>
                    <div class="red wrong"></div>
                    <div class="green right"></div>
                </div>
            </div>
        </div>
        <script src="js/jquery.js"></script>
        <script src="js/jquery-ui.min.js"></script>
        <script src="js/custom.js"></script>
    </body>
</html>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-24 02:38:29

看上去反弹影响不喜欢相对定位和利润率。

试试这个CSS:

代码语言:javascript
复制
   html {
    height: 100%;
    width: 100%
}

body {
    margin: 0;
    padding: 0;
    text-align:center;
    height: 100%;
    width: 100%;
}

#level1 {
    position: absolute;
    background-color: lightgrey;
    height: 100%;
    margin: 0;
    padding: 0;  
    width: 100%;  
}

#level2 {
    position: absolute;
    height: 100%;
    display: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

.inner-container {
    position: absolute;
    height: 100%;
    width: 100%;
    border: thin black solid;
}

.question {
    text-align: center;
    font-size: 20px;
    padding-top: 5%;
    margin: 0;
}

.circles {
    text-align: center;
}

.red {
    position: absolute;
    top: 300px;
    left: 30%;
    height: 100px;
    width: 100px;
    border-radius: 100%;
    background-color: red;
}

.blue {
    position: absolute;
    top: 300px;
    left: 45%;
    height: 100px;
    width: 100px;
    border-radius: 100%;
    background-color: blue;
}

.green {
    position: absolute;
    top: 300px;
    left: 60%;
    height: 100px;
    width: 100px;
    border-radius: 100%;
    background-color: green;
}

我在本地运行,看起来很管用。

编辑:您可能需要关闭边框。我把它们打开,这样我就能看到球在里面的容器了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31601127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档