javascript - 使用 jQuery 以设定的间隔移动和 HTML div
问题描述
我有加载其中内容的图像。现在,每次执行设置的间隔计数器时,我都希望 div 向左 500 像素设置动画,而不仅仅是出现和消失。我正在使用 jquery。我现在拥有它,以便它附加到内容 div。
function nextItem(){
counter ++;
$content.empty();
if(counter <= 3){
var $current = '<div id="item" style="background-image: url(' + images[counter].image + ');"><p id="title"> ' + images[counter].title + ' </p><p id="caption"> ' + images[counter].caption + ' </p></div>';
var $next = '<div id="item" style="background-image: url(' + images[counter + 1].image + ')"><p id="title"> ' + images[counter + 1].title + ' </p><p id="caption"> ' + images[counter + 1].caption + ' </p></div>'
$content.append($current);
$content.append($next);
}
if(counter > 3){
counter = 0;
var $current = '<div id="item" style="background-image: url(' + images[counter].image + ');"><p id="title"> ' + images[counter].title + ' </p><p id="caption"> ' + images[counter].caption + ' </p></div>';
var $next = '<div id="item" style="background-image: url(' + images[counter + 1].image + ')"><p id="title"> ' + images[counter + 1].title + ' </p><p id="caption"> ' + images[counter + 1].caption + ' </p></div>'
$content.append($current);
$content.append($next);
}
}
我试着把它写成'
$content.append($current).animate({right:'400px'});
但它没有用
解决方案
推荐阅读
- android - Android Studio 检查您到目前为止编写了多少代码的方法
- angular - 尝试以角度构建 docker 映像时出错
- java - 从firebase检索图像以在片段中的回收器视图时出错
- mysql - MySQL 数据库中的“Horse Table”不起作用?
- arrays - Google 表格 - 使用 ARRAYFORMULA 并基于另一个字段的值增加单元格值
- api - 如何通过“TBA”编号跟踪亚马逊包裹?
- python - 如何将嵌套列表映射到 Python 中的可迭代字典
- powershell - 获取命令和版本号
- c# - 为什么 FileSystemWatcher 事件没有触发
- javascript - 如何通过模板文字中的回调函数发送json数据?