首页 > 解决方案 > 使用 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'});

但它没有用

标签: javascriptjquerycss

解决方案


推荐阅读