--------------------------------------------------------------------------------
var Drag={
obj: null,
leftTime: null,
rightTime: null,
init: function (o,minX,maxX,btnRight,btnLeft) {
o.onmousedown=Drag.start;
o.hmode=true;
if(o.hmode&&isNaN(parseInt(o.style.left))) { o.style.left="0px"; }
if(!o.hmode&&isNaN(parseInt(o.style.right))) { o.style.right="0px"; }
o.minX=typeof minX!='undefined'?minX:null;
o.maxX=typeof maxX!='undefined'?maxX:null;
o.onDragStart=new Function();
o.onDragEnd=new Function();
o.onDrag=new Function();
btnLeft.onmousedown=Drag.startLeft;
btnRight.onmousedown=Drag.startRight;
btnLeft.onmouseup=Drag.stopLeft;
btnRight.onmouseup=Drag.stopRight;
},
start: function (e) {
var o=Drag.obj=this;
e=Drag.fixE(e);
var x=parseInt(o.hmode?o.style.left:o.style.right);
o.onDragStart(x);
o.lastMouseX=e.clientX;
if(o.hmode) {
if(o.minX!=null) { o.minMouseX=e.clientX-x+o.minX; }
if(o.maxX!=null) { o.maxMouseX=o.minMouseX+o.maxX-o.minX; }
} else {
if(o.minX!=null) { o.maxMouseX= -o.minX+e.clientX+x; }
if(o.maxX!=null) { o.minMouseX= -o.maxX+e.clientX+x; }
}
document.onmousemove=Drag.drag;
document.onmouseup=Drag.end;
return false;
},
drag: function (e) {
e=Drag.fixE(e);
var o=Drag.obj;
var ex=e.clientX;
var x=parseInt(o.hmode?o.style.left:o.style.right);
var nx;
if(o.minX!=null) { ex=o.hmode?Math.max(ex,o.minMouseX):Math.min(ex,o.maxMouseX); }
if(o.maxX!=null) { ex=o.hmode?Math.min(ex,o.maxMouseX):Math.max(ex,o.minMouseX); }
nx=x+((ex-o.lastMouseX)*(o.hmode?1:-1));
$("scrollcontent").style[o.hmode?"left":"right"]=(-nx*barUnitWidth)+"px";
Drag.obj.style[o.hmode?"left":"right"]=nx+"px";
Drag.obj.lastMouseX=ex;
Drag.obj.onDrag(nx);
return false;
},
startLeft: function () {
Drag.leftTime=setInterval("Drag.scrollLeft()",1);
},
scrollLeft: function () {
var c=$("scrollcontent");
var o=$("scrollbar");
if((parseInt(o.style.left.replace("px",""))<(590-162-10))&&(parseInt(o.style.left.replace("px",""))>=0)) {
o.style.left=(parseInt(o.style.left.replace("px",""))+1)+"px";
c.style.left=(-(parseInt(o.style.left.replace("px",""))+1)*barUnitWidth)+"px";
} else {
Drag.stopLeft();
}
},
stopLeft: function () {
clearInterval(Drag.leftTime);
},
startRight: function () {
Drag.rightTime=setInterval("Drag.scrollRight()",1);
},
scrollRight: function () {
var c=$("scrollcontent");
var o=$("scrollbar");
if((parseInt(o.style.left.replace("px",""))<=(590-162-10))&&(parseInt(o.style.left.replace("px",""))>0)) {
o.style.left=(parseInt(o.style.left.replace("px",""))-1)+"px";
c.style.left=(-(parseInt(o.style.left.replace("px",""))-1)*barUnitWidth)+"px";
} else {
Drag.stopRight();
}
},
stopRight: function () {
clearInterval(Drag.rightTime);
},
end: function () {
document.onmousemove=null;
document.onmouseup=null;
Drag.obj.onDragEnd(parseInt(Drag.obj.style[Drag.obj.hmode?"left":"right"]));
Drag.obj=null;
},
fixE: function (e) {
if(typeof e=='undefined') { e=window.event; }
if(typeof e.layerX=='undefined') { e.layerX=e.offsetX; }
return e;
}
};
var scrollbar = $('scrollbar');
var scrollleft = $('scrollleft');
var scrollright = $('scrollright');
if(scrollbar&&scrollright){
Drag.init(scrollbar,0,418,scrollleft,scrollright);
}
function hideRecommended() {
($("tab").style.display=="none")?($("tab").style.display=""):($("tab").style.display="none");
($("tab").style.display=="none")?($("hidebar").style.backgroundImage="url(icon_46.gif)"):($("hidebar").style.backgroundImage="url(icon_47.gif)");
}
--------------------------------------------------------------------------------上面是JS内容,我想在网页当中通过下面的方式得到barUnitWidth的值。高手些救命。<script type="text/javascript">
var barUnitWidth=得到这个值,这里写什么语句呢;
</script>
直接使用就是了:
alert(barUnitWidth);
<script type="text/javascript">
var barUnitWidth=1.41148325359;
</script>他得到的是一个数字。
var Drag={
obj: null,
leftTime: null,
rightTime: null,
init: function (o,minX,maxX,btnRight,btnLeft) {
o.onmousedown=Drag.start;
o.hmode=true;
if(o.hmode&&isNaN(parseInt(o.style.left))) { o.style.left="0px"; }
if(!o.hmode&&isNaN(parseInt(o.style.right))) { o.style.right="0px"; }
o.minX=typeof minX!='undefined'?minX:null;
o.maxX=typeof maxX!='undefined'?maxX:null;
o.onDragStart=new Function();
o.onDragEnd=new Function();
o.onDrag=new Function();
btnLeft.onmousedown=Drag.startLeft;
btnRight.onmousedown=Drag.startRight;
btnLeft.onmouseup=Drag.stopLeft;
btnRight.onmouseup=Drag.stopRight;
},
start: function (e) {
var o=Drag.obj=this;
e=Drag.fixE(e);
var x=parseInt(o.hmode?o.style.left:o.style.right);
o.onDragStart(x);
o.lastMouseX=e.clientX;
if(o.hmode) {
if(o.minX!=null) { o.minMouseX=e.clientX-x+o.minX; }
if(o.maxX!=null) { o.maxMouseX=o.minMouseX+o.maxX-o.minX; }
} else {
if(o.minX!=null) { o.maxMouseX= -o.minX+e.clientX+x; }
if(o.maxX!=null) { o.minMouseX= -o.maxX+e.clientX+x; }
}
document.onmousemove=Drag.drag;
document.onmouseup=Drag.end;
return false;
},
drag: function (e) {
e=Drag.fixE(e);
var o=Drag.obj;
var ex=e.clientX;
var x=parseInt(o.hmode?o.style.left:o.style.right);
var nx;
if(o.minX!=null) { ex=o.hmode?Math.max(ex,o.minMouseX):Math.min(ex,o.maxMouseX); }
if(o.maxX!=null) { ex=o.hmode?Math.min(ex,o.maxMouseX):Math.max(ex,o.minMouseX); }
nx=x+((ex-o.lastMouseX)*(o.hmode?1:-1));
$("scrollcontent").style[o.hmode?"left":"right"]=(-nx*barUnitWidth)+"px";
Drag.obj.style[o.hmode?"left":"right"]=nx+"px";
Drag.obj.lastMouseX=ex;
Drag.obj.onDrag(nx);
return false;
},
startLeft: function () {
Drag.leftTime=setInterval("Drag.scrollLeft()",1);
},
scrollLeft: function () {
var c=$("scrollcontent");
var o=$("scrollbar");
if((parseInt(o.style.left.replace("px",""))<(590-162-10))&&(parseInt(o.style.left.replace("px",""))>=0)) {
o.style.left=(parseInt(o.style.left.replace("px",""))+1)+"px";
c.style.left=(-(parseInt(o.style.left.replace("px",""))+1)*barUnitWidth)+"px";
} else {
Drag.stopLeft();
}
},
stopLeft: function () {
clearInterval(Drag.leftTime);
},
startRight: function () {
Drag.rightTime=setInterval("Drag.scrollRight()",1);
},
scrollRight: function () {
var c=$("scrollcontent");
var o=$("scrollbar");
if((parseInt(o.style.left.replace("px",""))<=(590-162-10))&&(parseInt(o.style.left.replace("px",""))>0)) {
o.style.left=(parseInt(o.style.left.replace("px",""))-1)+"px";
c.style.left=(-(parseInt(o.style.left.replace("px",""))-1)*barUnitWidth)+"px";
} else {
Drag.stopRight();
}
},
stopRight: function () {
clearInterval(Drag.rightTime);
},
end: function () {
document.onmousemove=null;
document.onmouseup=null;
Drag.obj.onDragEnd(parseInt(Drag.obj.style[Drag.obj.hmode?"left":"right"]));
Drag.obj=null;
},
fixE: function (e) {
if(typeof e=='undefined') { e=window.event; }
if(typeof e.layerX=='undefined') { e.layerX=e.offsetX; }
return e;
}
};
var scrollbar = $('scrollbar');
var scrollleft = $('scrollleft');
var scrollright = $('scrollright');
if(scrollbar&&scrollright){
Drag.init(scrollbar,0,418,scrollleft,scrollright);
}
function hideRecommended() {
($("tab").style.display=="none")?($("tab").style.display=""):($("tab").style.display="none");
($("tab").style.display=="none")?($("hidebar").style.backgroundImage="url(http://img.ifeng.com/hdslide/icon_46.gif)"):($("hidebar").style.backgroundImage="url(http://img.ifeng.com/hdslide/icon_47.gif)");
}
各位高手,上面的文件已经对我提出的问题有关联吧???如果是上面的代码,如何实现我说的这个功能呢。<script type="text/javascript">
var barUnitWidth=1.41148325359;
</script>