在Webkit浏览器上使用jQuery读取和设置z-index值 [英] Reading and setting z-index values with jQuery on Webkit browsers

查看:187
本文介绍了在Webkit浏览器上使用jQuery读取和设置z-index值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery(#X)。css(z-index); 总是在Webkit浏览器上返回auto

jQuery("#X").css("z-index"); always returns "auto" on Webkit browsers. Works ok on Firefox.

您似乎无法使用以下类似的方式设置z-index: jQuery(#X) .css(z-index,5);

It also appears that you can't set the z-index with something like: jQuery("#X").css("z-index",5);

测试用例如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>jQuery CSS Z-index Fail</title>
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $("#X").css("z-index",5);       
        $("#Y").append($("#X").css("z-index"));
      });
    </script>
    <style type="text/css">
      h1 {z-index: 3;}
    </style>
  </head>
  <body>
     <h1 id="X">Some Text</h1>
     <div id="Y"> Z-index is: </div>
  </body>
</html>


推荐答案

您需要指定使用z-index的位置。

You NEED to specify position to use z-index.

<h1 id="X" style='position:relative;'>Some Text</h1>

立即在Chrome中修复。

fixes it immediately in Chrome.

这篇关于在Webkit浏览器上使用jQuery读取和设置z-index值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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