javascript求解释````

慕容奇樱 2012-07-26 04:05:47
<style type="text/css">
* { margin:0; padding:0; }
body {
margin:5px auto;
text-align:center;
background:#f0f0f0;
}
img { margin:0; border:0; padding:0; }
#eLore {
position:relative;
margin:0 auto;
width:800px; height:339px;
}
#eLore_wrap {
position:relative;
margin:0 auto;
overflow:hidden;
width:800px; height:339px;
background:#369;
}
#eLore .eLore_img {
position:absolute; top:0;
width:120px; height:339px;
overflow:hidden;
font-size:50px;
line-height:340px;
}
#eLore .eLore_out {
position:absolute; top:0;
width:120px; height:339px;
overflow:hidden;
font-size:10px;
line-height:340px;
}
</style>
</head>
<body>
<div id="eLore">
<div id="eLore_wrap">Loading...</div>
</div>
<script type="text/javascript">
//<[CDATA[
var eLore_wrap = document.getElementById('eLore_wrap');
var aImg = new Array('112_jpg_thum.jpg','123_jpg_thum.jpg','112_jpg_thum.jpg', '123_jpg_thum.jpg');
var iImg = 0;
var iA = 0;
window.onload = function() {
eLore_createD();
}
function eLore_createD() {
if (iImg==10) {
eLore_wrap.innerHTML = '';
iImg = 0;
}
if (iImg==0) {
eLore_wrap.innerHTML += '<div class="eLore_out" style="right:0px; background:url(' + aImg[iA] + ') -680px top no-repeat;">H</div>\n';
}
/*
var sDiv = '<div class="eLore_img" style="left:' + (720-iImg*80) + 'px; background:url(' + aImg[iA] + ') -720px top no-repeat;">' + iImg++ + '</div>\n';
eLore_wrap.innerHTML += sDiv;
*/
var oDiv = document.createElement('div');
oDiv.className = 'eLore_img';
oDiv.style.right = iImg*80 +'px';
oDiv.style.background = 'url(' + aImg[iA] + ') -720px top no-repeat';
//oDiv.appendChild(document.createTextNode(iImg));
eLore_wrap.appendChild(oDiv);
iImg++;
eLore_move();
}
function eLore_move(){
var oDiv = eLore_wrap.getElementsByTagName('div');
for (var i=1; i<oDiv.length; i++) {
var iBgpx = parseInt(oDiv[i].style.backgroundPosition);
if (iBgpx<i*80-760) {
var iMovePx = Math.floor((760-i*80+iBgpx)/15);
oDiv[i].style.backgroundPosition = iBgpx - iMovePx + 'px top';
} else {
oDiv[i].style.backgroundPosition = '-' + (760- i*80) + 'px top';
}
}
if (iImg<10) {
setTimeout('eLore_createD()','50');
} else if (parseInt(oDiv[10].style.backgroundPosition)<40) {
setTimeout('eLore_move()','50');
} else {
iA = ++iA==aImg.length ? 0 : iA;
setTimeout('eLore_createD()','2000');
}
}
//]]>
</script>



请求高手为我解释 eLore_move()方法中: var iMovePx = Math.floor((760-i*80+iBgpx)/15);
还有最后一句
else {
iA = ++iA==aImg.length ? 0 : iA;
setTimeout('eLore_createD()','2000');
}
的意思。顺便帮我也解释下这段代码的编程思路~···
...全文
181 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hch126163 2012-07-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 1 楼 的回复:

Math.floor((760-i*80+iBgpx)/15); 是进行去余取整,向下的 不是四舍五入 760减i乘以80+iBgpx然后除以15以后取整

iA = ++iA==aImg.length ? 0 : iA;
setTimeout('eLore_createD()','2000');


iA+1 == aImg.length
如果相……
[/Quote]

那找那么多为什么啊

你喜欢完全可以改成 其它的数字。自己试试啊
慕容奇樱 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Math.floor((760-i*80+iBgpx)/15); 是进行去余取整,向下的 不是四舍五入 760减i乘以80+iBgpx然后除以15以后取整

iA = ++iA==aImg.length ? 0 : iA;
setTimeout('eLore_createD()','2000');


iA+1 == aImg.length
如果相等的话iA = 0 ;
……
[/Quote]麻烦解释下为啥是除以15
慕容奇樱 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Math.floor((760-i*80+iBgpx)/15); 是进行去余取整,向下的 不是四舍五入 760减i乘以80+iBgpx然后除以15以后取整

iA = ++iA==aImg.length ? 0 : iA;
setTimeout('eLore_createD()','2000');


iA+1 == aImg.length
如果相等的话iA = 0 ;
……
[/Quote] 最后一句我看得懂,不过我不明白 等不等都等于0 啊 ,ia有在变吗?
温柔哥 2012-07-26
  • 打赏
  • 举报
回复
Math.floor((760-i*80+iBgpx)/15); 是进行去余取整,向下的 不是四舍五入 760减i乘以80+iBgpx然后除以15以后取整

iA = ++iA==aImg.length ? 0 : iA;
setTimeout('eLore_createD()','2000');


iA+1 == aImg.length
如果相等的话iA = 0 ;
如果不相等的话iA = iA;
然后是一个延迟函数, 2000=2秒后执行函数eLore_createD();

87,992

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧