部分覆盖屏幕并滑动叠加元素 [英] Partial cover the screen and slide the overlay-element

查看:136
本文介绍了部分覆盖屏幕并滑动叠加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建一个overlay-div,它覆盖整个屏幕 - 除了3em到底部。我认为我的尝试不是最佳的:

I try to create an overlay-div, which covers the whole screen - except 3em to the bottom. I think my attempt is not the optimum:

<div id="background"></div>
<div id="overlay"></div>

CSS

#background {
    background-color: #ddd;
    width: 100%;
    height: 100%;
}

#overlay {
    position: absolute;
    height: 100%;
    background-color: #fff;
    width: 100%;
    top: -3em;
    -webkit-box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.3);
    -moz-box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.3);
    box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.3);
    z-index: 1;
}

这样,我想向上和向下滑动叠加。但是用上面的CSS,我不知道如何完全动画,因为'-55em'是太多的较低的屏幕分辨率或不够的更高的分辨率:

With that, I want to slide up and down the overlay. But with the css above, I don't know how to animate completely as '-55em' are too much on lower screen resolution or not enough on higher resolution:

JS:

JS:

$('#overlay').animate({'top':'-55em'}, 1000, function() {
    $('#overlay').animate({'top':'-3em'}, 1000);
});


推荐答案

我认为你应该改变高度,保存您的典型计算

i think you should change height instead of top it will save you from typical calculations

$('#overlay').animate({'height':'0%'}, 1000, function() {
	$('#overlay').animate({'height':'100%'}, 1000);
});

	#background {
		background-color: #ddd;
		width: 100%;
		height: 100%;
	}

	#overlay {
		position: absolute;
		height: 100%;
		background-color: #fff;
		width: 100%;
		top: -3em;
		-webkit-box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.3);
		-moz-box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.3);
		box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.3);
		z-index: 1;
	}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="background"></div>
	<div id="overlay"></div>

这篇关于部分覆盖屏幕并滑动叠加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆