javascript - 使用 JQuery 淡入 JSON ajax 列表

标签 javascript jquery

我有以下 slider :

https://jsfiddle.net/lucasmosele/px9ar93y/1/

我的间隔代码如下:

var counter = 1;
var elements = json.slider.length;

// Set timer between quotes being visible
$("#quotes li:first-child").addClass("active");
int = setInterval(function(){
        $("#quotes li:nth-child(" + counter + ")").removeClass("active");
        $("#quotes li:nth-child(" + counter + ")").next().addClass("active");
    if (counter === elements){
        counter = 1;
    } else {
        counter++;
    }
}, 3000);

我希望能够让新内容淡入,我已经尝试过.fadeIn:

$("#quotes li:nth-child(" + counter + ")").next().addClass("active").fadeIn("slow");

但我得到了我不一定想要的行为。我还尝试在 li 和 li.active 之间创建 css 过渡,但由于某种原因,除非 .fadeIn 设置为“慢”,否则它们不会显示。

有没有更干净的方法来做到这一点?

最佳答案

你可以做到

$("#quotes li:nth-child(" + counter + ")").next().hide().addClass("active").fadeIn("slow");

Play it here

关于javascript - 使用 JQuery 淡入 JSON ajax 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33786623/

相关文章:

jquery - 尝试理解这个代码块

javascript - 在 Opera User JavaScript 中使用 jQuery

javascript - 如何从使用 jquery 动态创建的视频标签获取视频持续时间?

javascript - 如何使用 Javascript 更改 @font-face 源?

javascript - 在 javascript 中使用 fetch 时访问 header

javascript - 在构建 ajax 应用程序时放弃 <form> 标记是否合适?

javascript - jQuery 点击事件不会解除绑定(bind)

javascript - jquery 不显示事件命名空间

javascript - 如何根据鼠标点击裁剪选定的矩形

javascript - 如何使用 Google App Script 将格式化文本从 google 工作表单元格保存到 .rtf?