如何在背景中保留动画,在另一个元素后面
How do I keep animations in the background, behind another element?
我正在尝试使用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;
http://jsfiddle.net/HerrSerker/wppFq/2/您需要为slide1和按钮
相关文章:
- 使用clickToggle并在单击另一个元素时关闭元素
- 按我自己的类克隆另一个元素的内容和顺序
- 如何通过HTML+CSS中的另一个元素Selector更改元素的属性值
- jQuery-将列表项的一个元素移动到同一项的另一个元素中+对我的列表中的每个项执行此操作
- jquery从另一个元素中移除移除
- DIV怎么能像Javascript中的另一个元素一样工作呢
- 使用数据属性将HTML数据复制到另一个元素
- 将鼠标悬停在Angular JS中的一个元素上,并将Class添加到另一个元素中
- 在类JavaScript选择的另一个元素中选择一个标记元素
- 只要存在,就用另一个元素替换一个元素
- 初学者反应查询(如何删除一个元素并附加另一个元素)
- 将jquery ui窗口的父元素设置为另一个元素
- 如何激活下拉菜单:在一个元素上单击768px宽度下方,在另一个元素上将鼠标悬停在768px上方
- Pixijs将元素附加到另一个元素
- JavaScript:将输入范围行为链接到另一个元素
- 如何使用元素's属性值,以针对jQuery中具有相同属性值的另一个元素
- angularjs阵列拼接到另一个元素
- 另一个元素JAVAscript中的元素位置
- 当鼠标也在触摸另一个元素时,d3.js鼠标悬停事件未被触发
- 将元素的可见性绑定到另一个元素