jQuery水平和垂直定位脚本在IE8中不起作用
jQuery horizontal and vertical positioning script not working in IE8
这是设计http://vvcap.net/db/OuxLOYioWmjIAavL5N9U.htp
这是一个演示!http://designobvio.us/GoldGrid2/
我正在尝试让一个垂直和水平的jQuery脚本在IE8上运行:
脚本代码
<script type="text/javascript">
$(document).ready(function(){
$(window).resize(function(){
$('.padder').css({
position:'absolute',
left: ($(window).width()
- $('.padder').outerWidth())/2,
top: ($(window).height()
- $('.padder').outerHeight())/2
});
});
// To initially run the function:
$(window).resize();
});
</script>
关于为什么这个脚本在IE8中不起作用的任何想法?
您可能希望将高度和宽度声明为数字,以便确定数学可以正常工作,并且由于您要更改 CSS,因此值需要是包含"px"的字符串
left: ((Number($(window).width()) - Number($('.padder').outerWidth()))/2)+'px',
top: ((Number($(window).height()) - Number($('.padder').outerHeight()))/2)+'px'
按照这些思路,我可能会在 CSS 之前设置值。
var leftVal = Number($(window).width()) - Number($('.padder').outerWidth())/2;
var topVal = Number($(window).height()) - Number($('.padder').outerHeight()))/2;
然后:
left: leftVal+'px',
top: topVal+'px'
全功能:
$(window).resize(function(){
var leftVal = Number($(window).width()) - Number($('.padder').outerWidth())/2;
var topVal = Number($(window).height()) - Number($('.padder').outerHeight()))/2;
$('.padder').css({
position:'absolute',
left: leftVal+'px',
top: topVal+'px'
});
});
相关文章:
- Recaptcha在IE7和IE8中不起作用
- 在IE8中不起作用的元素上触发单击事件
- 数据-在IE8中不起作用
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8 jquery ajax头请求不起作用
- 显示隐藏的html表在javascript(IE8)中不起作用
- ScriptX 打印功能在 IE8 中不起作用
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- ExtJs 5.0:forEach on Array of Objects在IE8中不起作用
- 将JSON对象转换为敲除observable在IE8中不起作用,但在所有其他浏览器中都起作用
- 聚焦函数在ie8中不起作用
- 启动网格在IE8中不起作用
- Svg标签在IE8中不起作用
- Twitter引导程序示例在IE8中不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- IE8的Javascript占位符不起作用
- Javascript中的开关案例在IE8中不起作用
- 如果我添加 pageX 页面 Y 在 IE8 中不起作用<!文档类型 html>.
- getElementsByTagName和getElementsByClassName在IE8中不起作用
- 导航在IE8上不起作用