首页 新闻 赞助 找找看

为什么图片不动

0
悬赏园豆:100 [待解决问题]

/// <reference path="..\jquery-1.4.1-vsdoc.js"/>
$(function () {
    var div = $("#content");
    change_div("content", 50, 50, 50, "blue");

    div.before($("<button>").html("move").attr("id", "move"));
    $("#move").click(function () { move_div(); });

 


    //    $(document).append(div)//
    //$(document).append(create_div("", 10, 10, 100, "b", "green"));

})


function move_div() {
    var a = ["250", "100", "150", "200", "250"];
    //alert(a[2]);
    //change_div("content", 50, 50, 150, "blue");
    //setTimeout(function () { change_div("content", 50, 50, 150, "blue"); }, 1000);

    for (var i = 0; i < a.length; i++) {
        //document.write(a[i]);
        //setTimeout(function () { change_div("content", 50, 50, a[i], "blue"); }, a[i] * 2);
        setTimeout(function () { $("#content").css("left", a[i]); }, i*1000);
    }
}

function change_div(oid, width, height, left, backgroundcolor) {
    var a = $("#" + oid + "");
    //a.addClass("pan");
    //a.html(content);
    a.css("width", width);
    a.css("position", "absolute");
    a.css("left", left);
    a.css("height", height);
    a.css("background-color", backgroundcolor);
    //a.attr("id", id);
    return a;
}

xinshenghu的主页 xinshenghu | 初学一级 | 园豆:105
提问于:2012-02-06 16:11
< >
分享
所有回答(2)
0
View Code
 1    var i = 0;
2 var intervalProcess;
3
4 $(function () {
5 var div = change_div("content", 50, 50, 50, "blue");
6
7 div.before($("<button>").html("move").attr("id", "move"));
8
9 $("#move").click(function () { intervalProcess = setInterval(move_div, 1000); });
10
11 })
12
13
14 function move_div() {
15 var a = [250, 100, 150, 200, 250];
16 $("#content").css("left", a[i]);
17 i++;
18 if (i > a.length) {
19 clearInterval(intervalProcess);
20 i = 0;
21 return false;
22
23 }
24 }
25
26 function change_div(oid, width, height, left, backgroundcolor) {
27 var a = $("#" + oid + "");
28 a.css("width", width);
29 a.css("position", "absolute");
30 a.css("left", left);
31 a.css("height", height);
32 a.css("background-color", backgroundcolor);
33 return a;
34 }
陈齐 | 园豆:311 (菜鸟二级) | 2012-02-08 23:57
0

gif图片能动

$飘渺$ | 园豆:221 (菜鸟二级) | 2012-02-20 15:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册