作者oao54bb (央)
看板Ajax
標題[問題] 變數初始化問題
時間Mon Apr 2 21:52:27 2012
這是我的程式碼:
var NN = 0; // 顯示筆數
var GOGO = 0; //移動座標位置
var times = 1; //切換筆數
$(".near ul").css({left:0});
$('.next').click(function(){
if(times<datas.length/10){ // 每次僅顯示10筆,直到沒有資料
NN+=10;
times+=1;
GOGO = NN*58*-1;
$(".near ul").stop().animate({left:GOGO},500);
}
});
$('.prev').click(function(){
if(NN>0){
NN-=10;
times-=1;
GOGO = NN*58*-1;
$(".near ul").stop().animate({left:GOGO},500);
}
});
這是一個左右轉動的照片輪播程式。
流程:
---------------------------------------------
┌┐ ┌┐ ┌┐ ┌┐ ┌┐ ┌┐ ┌┐
< └┘ └┘ └┘ └┘ └┘ └┘ └┘ >
---------------------------------------------
問題:
如何在下一次讀取 data前,
先將↓ 的NN、times,GOGO,animate({left:GOGO},500)
都先回歸到最原始的數值 0 ?
※在沒有重新整理的情況下
$('.next').click(function(){
if(times<datas.length/10){ // 每次僅顯示10筆,直到沒有資料
NN+=10;
times+=1;
GOGO = NN*58*-1;
$(".near ul").stop().animate({left:GOGO},500);
}
});
--
Blog
http://oao54bb.blogspot.com/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.240.34.196