关于JS的问题 求有高人解答

qazw88610406 2012-05-09 11:35:01
我在网上弄了个仿QQ的JS
但是 用起来有个问题 昨天弄了一下午 加今天早上 没找到 求有高人解答

问题就是 我点第一张图片 后面的图片用的 样式都是一样的 但是有些图片是长的 有些是宽的

这样的话 样式跟前面的 一样 有些图片就挤在一起 很难看

所以请大家帮我看看 怎么改 才会让他的背景 随着图片的大小而变动

天蓝色的部分 是改成自己图片文件的位置



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS+CSS仿QQ空间的图片展示效果丨芯晴网页特效丨CsrCode.Cn</title>
<style type="text/css">
html, body {height:100%;margin:0px;padding:0px;background:url(http://zf4uc1.chinaw3.com/js/img/images/bg.jpg);}
.box {width:850px;height:auto;overflow:hidden;margin:30px auto;background:#666;padding:10px 0 0 10px;}
.box ul {margin:0px;padding:0px;float:left;list-style-type:none;}
.box li {width:150px;height:100px;float:left;cursor:pointer;display:inline;margin:0 10px 10px 0;border:5px solid #333;}
#bg {width:100%;height:100%;position:absolute;left:0px;top:0px;background:#000;filter:alpha(opacity:50);opacity:0.5;display:none;}
#bottom {width:215px;height:50px;position:absolute;left:50%;bottom:0px;margin:0 0 0 -107px;border:1px solid #232323;background:#444;padding:1px;z-index:1;display:none;}
#bottom ul {width:100%;height:100%;margin:0px;padding:0px;list-style-type:none;background:#000;}
#bottom li {background:url(http://zf4uc1.chinaw3.com/js/img/images/ico.jpg) no-repeat;float:left;display:inline;margin:8px 0 0 18px;cursor:pointer;}
#bottom li.prev {width:30px;height:33px;background-position:0 0;}
#bottom li.next {width:30px;height:33px;background-position:-35px 0;}
#bottom li.img {width:30px;height:33px;background-position:-106px 0;}
#bottom li.close {width:31px;height:33px;background-position:-70px 0;}
#frame {background:#fff;padding:3px;position:absolute;z-index:2;display:none;filter:alpha(opacity:0);opacity:0; text-align:center;}
</style>
<script type="text/javascript">
function getStyle(obj, attr)
{
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj, false)[attr];
}
window.onload = function(){
var oBox = document.getElementById('box');
var oBg = document.getElementById('bg');
var oBot = document.getElementById('bottom');
var aBli = oBot.getElementsByTagName('li');
var oFrame = document.getElementById('frame');
var aLi = oBox.getElementsByTagName('li');
var aImg = oBox.getElementsByTagName('img');
var i = iNow = 0;
for(i=0;i<aLi.length;i++){
aLi[i].index = i;
aLi[i].onclick = function(){
with(oFrame.style){display = 'block',top = this.offsetTop +'px',left = this.offsetLeft +'px',width = this.offsetWidth +'px',height = this.offsetHeight +'px';}
oFrame.innerHTML = '<img src="http://zf4uc1.chinaw3.com/js/img/images/'+(this.index + 1)+'.jpg" />';
var oImg = oFrame.getElementsByTagName('img')[0];
var iWidth = oImg.width;
var iHeight = oImg.height;
var iLeft = parseInt((document.documentElement.clientWidth / 2) - (iWidth /2));
var iTop = parseInt((document.documentElement.clientHeight / 2) - (iHeight /2) - 50);
with(oImg.style){height = width = '100%';}
startMove(oFrame, {opacity:100, left:iLeft, top:iTop, width:iWidth, height:iHeight});
oBg.style.display = 'block';
oBot.style.display = 'block';
iNow = this.index + 1;
};
}
document.onmousedown = function(){
return false
};
aBli[0].onclick = function(){
iNow--;
if(iNow == 0)iNow = aLi.length;
oFrame.innerHTML = '<img src="http://zf4uc1.chinaw3.com/js/img/images/'+iNow+'.jpg" width="100%" height="100%" />';
};
aBli[1].onclick = function(){
oFrame.style.cursor = 'move';
oFrame.onmousedown = function(e){
var oEvent = e || event;
var X = oEvent.clientX - oFrame.offsetLeft;
var Y = oEvent.clientY - oFrame.offsetTop;
document.onmousemove = function(e){
var oEvent = e || event;
var L = oEvent.clientX - X;
var T = oEvent.clientY - Y;
if(L < 0){
L = 0;
}else if(L > document.documentElement.clientWidth - oFrame.offsetWidth){
L = document.documentElement.clientWidth - oFrame.offsetWidth
}
if(T < 0){
T = 0;
}else if(T > document.documentElement.clientHeight - oFrame.offsetHeight){
T = document.documentElement.clientHeight - oFrame.offsetHeight;
}
oFrame.style.left = L + 'px';
oFrame.style.top = T + 'px';
oFrame.style.margin = 0;
return false;
}
document.onmouseup = function(){
document.onmouseup = null;
document.onmousemove = null;
};
return false;
};
};
aBli[2].onclick = function(){
iNow++;
if(iNow > aLi.length)iNow = 1;
oFrame.innerHTML = '<img src="http://zf4uc1.chinaw3.com/js/img/images/'+iNow+'.jpg" width="100%" height="100%" />';
};
aBli[3].onclick = function(){
startMove(oFrame, {opacity:0, left:aImg[iNow-1].offsetLeft, top:aImg[iNow-1].offsetTop, width:150, height:100}, function(){
oFrame.style.display = 'none';
oBg.style.display = 'none';
oBot.style.display = 'none';
oFrame.onmousedown = null;
oFrame.style.cursor = 'auto';
});
};

};
function startMove(obj, json, onEnd){
clearInterval(obj.timer);
obj.timer=setInterval(function (){
doMove(obj, json, onEnd);
}, 30);
}
function doMove(obj, json, onEnd){
var attr='';
var bStop=true;
for(attr in json){
var iCur=0;
if(attr=='opacity'){
iCur=parseInt(parseFloat(getStyle(obj, attr))*100);
}else{
iCur=parseInt(getStyle(obj, attr));
}
var iSpeed=(json[attr]-iCur)/5;
iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);

if(json[attr]!=iCur){
bStop=false;
}
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')';
obj.style.opacity=(iCur+iSpeed)/100;
}else{
obj.style[attr]=iCur+iSpeed+'px';
}
}
if(bStop){
clearInterval(obj.timer);
if(onEnd){
onEnd();
}
}
}
</script>
</head>
<body>
<div class="box" id="box">
<ul>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/1.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/2.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/3.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/4.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/5.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/6.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/7.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/8.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/9.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/10.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/11.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/12.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/13.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/14.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/15.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/16.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/17.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/18.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/19.jpg" width="100%" height="100%"></li>
<li><img src="http://zf4uc1.chinaw3.com/js/img/images/20.jpg" width="100%" height="100%"></li>

</ul>
</div>
<div id="bg"></div>
<div id="bottom">
<ul>
<li class="prev"></li>
<li class="img"></li>
<li class="next"></li>
<li class="close"></li>
</ul>
</div>
<div id="frame"></div>
</body>
</html>


...全文
2458 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
风一样的大叔 2012-06-20
  • 打赏
  • 举报
回复
我在自己的电脑上试了下,发现IE9下没问题,楼主用的是什么浏览器啊?

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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