Home  >  Article  >  Web Front-end  >  用js来定义浏览器中一个左右浮动元素相对于页面主体宽度的位置的函数_javascript技巧

用js来定义浏览器中一个左右浮动元素相对于页面主体宽度的位置的函数_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:56:55765browse

首先这个元素position为fixed
top为(clientHeight-elem.offsetHeight)/2(即元素在浏览器的中间,这个是固定的)
left为(clientWidht-主体宽度)/2+主体宽度+左边距,左边距可以设为正数,也可以为负数,如果为负数时的绝对值 等于 主体宽度+elem.offsetWidht,那么元素就刚好浮动在页面主体的左边,设置为0时,刚好浮动在页面主体的右边
但是万恶的ie6不支持css中fixed属性,好在ie6可以通过expresion表达式来解决,万事大吉
具体看代码:

复制代码 代码如下:





Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn