- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 div。一个在前面,我想让后面的那个向右移动,然后回到第一个上面。我使用了 jQuery,但它会立即更改 z-index,然后继续将一个 div 向右移动并向左移动到其原始位置。这就是我尝试这样做的方式:
<!DOCTYPE html>
<html>
<head>
<style>
.block {
position: absolute;
background-color: #abc;
left: 0px;
top:30px;
width: 60px;
height: 60px;
margin: 5px;
}
.block1 {
position: absolute;
background-color: red;
left: 0px;
top:30px;
width: 60px;
height: 60px;
margin: 5px;
z-index: 999;
}
</style>
<script src="js/jquery-1.10.2.min.js"></script>
</head>
<body>
<div class="block" onmouseout="hide();"></div>
<div class="block1" onmouseover="show();"></div>
<script>
function show() {
$(".block").animate({left: '+=100px'}, 2000);
$(".block1").css('zIndex', '-10000');
$(".block").animate({left: '-=100px'}, 2000);
};
function hide() {
$(".block").animate({left: '+=100px'}, 2000);
$(".block1").css('zIndex', '10000');
$(".block").animate({left: '-=100px'}, 2000);
};
</script>
</body>
</html>
最佳答案
animate
方法是异步的。在完成第一个动画后,您必须通过向 animate
方法提供回调函数来更改 z-index:
function show() {
$(".block").animate({left: '+=100px'}, 2000, function() {
$(".block1").css('zIndex', '-10000');
$(".block").animate({left: '-=100px'}, 2000);
});
};
来自 .animate()
的文档:
.animate( properties [, duration ] [, easing ] <b>[, complete ]</b> )
complete
Type: Function()
A function to call once the animation is complete.
关于javascript - 如何将一个 <div> 移到另一个 <div> 前面,然后再移回来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17859259/
我对 Objective C 和 iOS 开发总体来说是新手。我正在尝试创建一个应用程序,它会发出 http 请求并在标签上显示内容。 当我开始测试时,我注意到标签是空白的,尽管我的日志显示我已经恢复
我实现了一个 MVP 应用程序。后退按钮工作正常。我想以编程方式回到以前的地方。我该怎么做? 我正在寻找类似的东西: clientFactory.getPlaceController().goBack
我想从 mySubView 制作后退按钮。我有带有按钮的付款ViewController,这个按钮使view.addSubview(WkWebView)。所以我可以打开 WkWebView 但我不可能
我有一个 master 分支,里面有很多不会发布的特性。我被要求从 master 中删除这些功能并创建一个包含它们的新分支,以便我们稍后可以 merge 回 master。 我采取的步骤是: 在 ma
如何禁用页面上的所有 onclick 事件,绑定(bind)我的自定义函数,并在执行后启用所有之前的事件? 我正在构建一个小书签,它应该适用于任何已加载的页面,并且我正在使用 jQuery 来处理我的
我正在尝试从 Spotify api 接收 token 。不幸的是,我一直收到 415。你能帮帮我,让我知道我做错了什么吗? const axios = require('axios'); const
我有一个提供上下文的函数: def buildContext(s:String)(request:RequestHeader):Future[Granite.Context] = { ....
我有一个列表,其中包含几个不同形状的 numpy 数组。我想将这个数组列表 reshape 为一个 numpy 向量,然后更改向量中的每个元素,然后将其 reshape 回原始数组列表。 例如: 输入
我目前有这个工作 fiddle - http://jsfiddle.net/B8Abd/ 我想在函数中使用 jquerys 淡出然后淡入。目前的代码是这样的: function chan
我有 2 个分支,一个是 main 分支,另一个是我正在开发一个 parallel 版本。 A --> B --> C (master) \ -> E --> F (parallel) pa
我试图从我的“ super 项目”中的文件目录中创建一个“子项目”以与其他人一起工作,但我一直在努力使其在 git subtree 中工作。 理想情况下,其他人可以在子项目上工作,然后我从上游更改中提
有没有其他人看到这个? 我正在使用带有回形针的 rails 3,当我上传 .doc 时,它的应用程序/msword 效果很好,但是当我上传 .docx 时,content_type 被保存为应用程序/
我是一名优秀的程序员,十分优秀!