jquery - 向上滑动之前更改文本

标签 jquery

我正在制作一个带有文本和背景动画的 slider ,但下面的代码首先更改文本,然后将其向上滑动。

如何解决这个问题?

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);

最佳答案

您需要使用callback function动画:

 $("#Fade").slideUp(1000, function() {
     // this runs after the animation has completed
     $("#text1").text(text1[index]);
     $("#text2").text(text2[index]);
     $("#Fade").slideDown(1000);
 });

关于jquery - 向上滑动之前更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52253820/

相关文章:

javascript - 下拉菜单(SELECT 元素)在 IE6 中没有正确失去焦点

javascript - 上层div的百分比?

javascript - Angular 6 + jQuery + fullpage.js

jquery - 动态更改 Jquery UI 可排序助手?

javascript - 对方法或属性访问的意外调用。 jquery.js?ver=1.7.1

jquery - 使用 qTip jQuery 插件进行 ASP.NET MVC 验证

javascript - 如何在日期选择器中显示下个月和上个月的名称,而不仅仅是箭头 <,>

javascript - jQuery appendTo 在 Firefox 上断开链接

jquery - 动态添加的元素不换行

javascript - 如何替换不在特定 div 中的字符串?