gpt4 book ai didi

jQuery .effect() 搞乱了网页样式

转载 作者:行者123 更新时间:2023-11-28 07:29:42 25 4
gpt4 key购买 nike

我是一名初学者,尝试从事小型元素进行练习。我一直在为我儿子开发一个小游戏,但 jQuery .effect() 动画有一个小问题。单击正确的 div 时,它会显示 .effect('bounce') 动画,但会弄乱 div 在页面上的位置。 Here is the link to the game.我怎样才能阻止这种情况发生?我假设在我的 CSS 中进行了编辑。

抱歉,如果我没有快速回复,我会在 sleep 前发布这个(尝试整晚解决这个问题),提前致谢!

$(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');
});
});
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%;
}
<!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>

最佳答案

看起来反弹效果不喜欢相对定位和边距。

试试这个 CSS:

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

我在本地运行它,看起来它有效。

编辑:您可能想要关闭边框。我只是打开它们,以便我可以看到球所在的容器。

关于jQuery .effect() 搞乱了网页样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31601127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com