jquery - 向上滑动前更改文本
问题描述
我正在制作带有文本和背景动画的滑块,但下面的代码首先更改文本,然后将其向上滑动。
我该如何解决这个问题?
var index = 0;
var images = ["images/mainimage.jpg", "images/rampcustomers.jpg"];
var text1 = ["Connect all your devices and data bases", "Lorem ipsum dolor sit amet,"];
var text2 = ["Keep the efficiency managed and always up-to-date", "Lorem ipsum dolor sit amet"];
setInterval(function() {
index++;
if (index >= 2) {
index = 0;
}
$('#container1').animate({
opacity: 0.5
}, 'slow', function() {
$(this).css({
'background-image': 'url(' + images[index] + ')'
})
.animate({
opacity: 1
});
});
$("#Fade").slideUp(1000);
$("#text1").text(text1[index]);
$("#text2").text(text2[index]);
$("#Fade").slideDown(1000);
}, 4000);
解决方案
你需要使用动画的回调函数:
$("#Fade").slideUp(1000, function() {
// this runs after the animation has completed
$("#text1").text(text1[index]);
$("#text2").text(text2[index]);
$("#Fade").slideDown(1000);
});
推荐阅读
- python - 同步方法之间的通信
- postgresql - PostgreSQL LISTEN/NOTIFY 具有相同有效负载的每个事务的通知数
- javascript - 在 ReactJS 的子组件中将变量传递给处理程序
- r - 从 R 将记录附加到 SQL Server 中的表
- intellij-idea - 如何在 PhpStorm for JSX 上拆分和加入标签?例如:“ ”到“ ”
- python - SciPy Griddata“得到参数‘方法’的多个值”错误
- google-analytics - 如何在 Google Analytics 上更改网站所有者?
- codeigniter - 记录了codeigniter错误:同时针对文件夹中的所有文件“语言文件不包含数据”
- html - css flexbox布局模块中的表格设计
- python - AttributeError:实例仅在 Linux 中没有属性错误