javascript - 如何将动画保留在背景中,在另一个元素后面?

标签 javascript jquery css html

我正在尝试使用 HTML/jQuery 创建一个按钮,该按钮位于屏幕的中间左侧,并悬停在显示的所有其他内容上。我有一个 html5 过渡动画,可以在屏幕上移动一个元素。动画出现在按钮的顶部,这是我不想要的。我已经尝试使用绝对定位设置 z 顺序,但动画仍然出现在按钮上。

如何将按钮放置在屏幕上的某个位置并让所有动画显示在其下方?

下面是一些演示问题的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />        
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>                
    <style>
        pre {
            margin-top:0px;
            margin-bottom:0px;          
        }

        .button {
           border-top: 1px solid #96d1f8;
           background: #65a9d7;
           background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
           background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
           background: -moz-linear-gradient(top, #3e779d, #65a9d7);
           background: -ms-linear-gradient(top, #3e779d, #65a9d7);
           background: -o-linear-gradient(top, #3e779d, #65a9d7);
           padding: 5.5px 11px;
           -webkit-border-radius: 40px;
           -moz-border-radius: 40px;
           border-radius: 40px;
           -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
           -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
           box-shadow: rgba(0,0,0,1) 0 1px 0;
           text-shadow: rgba(0,0,0,.4) 0 1px 0;
           color: white;
           font-size: 24px;
           font-family: 'Lucida Grande', Helvetica, Arial, Sans-Serif;
           text-decoration: none;
           vertical-align: middle;
           }
        .button:hover {
           border-top-color: #28597a;
           background: #28597a;
           color: #ccc;
           }
        .button:active {
           border-top-color: #1b435e;
           background: #1b435e;
           }        

        .container {
            position:relative;
            left:0px;
            display: inline-block;
            padding: 15px;
            background-color: #d8e8f8;
            opacity: 100;
            -webkit-transition:all 1.0s ease-in-out;
            -moz-transition:all 1.0s ease-in-out;
            -o-transition:all 1.0s ease-in-out;
            -ms-transition:all 1.0s ease-in-out;        
            transition:all 1.0s ease-in-out;
        }
    </style>                
</head>
<script>
    $(document).ready(function() {

          function moveSlideLeft(id) {

            var percentage = "translate(-100%, 0px)";
            $(id).css("-webkit-transform",percentage);
            $(id).css("-moz-transform",percentage);
            $(id).css("-o-transform",percentage);
            $(id).css("-ms-transform",percentage);          
            $(id).css("transform",percentage);          
          }       


        $("#slide1").click(function() {
            moveSlideLeft("#container1");
        });
    }); 
</script>   
<body>      

<div class="button" style="float: left">The button</div>

<div id="container1" class="container">
<div id="slide1">

<pre>
Stuff.......................................
Stuff.......................................
Stuff.......................................
</pre>

</div>
</div>
</body>
</html>

最佳答案

因为 .container 上有 position: relative;,所以你需要 position: relative;z-index 在按钮上:

position: relative;
z-index: 10;

关于javascript - 如何将动画保留在背景中,在另一个元素后面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7779188/

相关文章:

javascript - 极其简单的Ajax代码不起作用

c# - 调试javascript代码

javascript - 函数覆盖类而不是添加新的

javascript - 带有换行转义字符的字符串会破坏 Javascript 脚本

javascript - 请求 REST 服务

javascript - 用javascript定位是一个好习惯

javascript - 淡化图像循环 jQuery

css - 文本框的水平滚动条

javascript - 如何在 JavaScript 或 jQuery 中查找 url 参数,然后应用事件监听器?

php - 为什么在 ajax 请求中使用 JSON 或者为什么不使用