我正在尝试将div从小尺寸设置为全屏尺寸然后隐藏,但问题是,它没有居中,宽度和高度不一样,我该如何处理它,有人可以建议吗?
这是我到目前为止所创造的:
$(document).ready(function() {
$( ".circle-centered" ).animate({
width:"100%",
height:"100%",
marginTop: -$('.circle-centered').outerHeight()/2
}, 5000);
});
.circle-centered {
width: 20px;
height: 20px;
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
top: 50%;
margin-top: -10px;
border-radius: 50%;
z-index: 3;
background: #ff0000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="circle-centered"></div>
答案 0 :(得分:3)
您需要为“top”属性设置动画,因为它将其设置为50%
$(document).ready(function() {
$( ".circle-centered" ).animate({
width:"100%",
height:"100%",
top:0,
marginTop: -$('.circle-centered').outerHeight()/2
}, 5000);
});
.circle-centered {
width: 20px;
height: 20px;
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
top: 50%;
margin-top: -10px;
border-radius: 50%;
z-index: 3;
background: #ff0000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="circle-centered"></div>
答案 1 :(得分:0)