html文件中有一段JS代码,如何把这段JS代码单独写成一个JS文件,然后在html中调用它呢 5
<scripttype="text/javascript">varglide=newfunction(){function$id(id){returndocument.g...
<script type="text/javascript">
var glide =new function(){
function $id(id){return document.getElementById(id);};
this.layerGlide=function(auto,oEventCont,oTxtCont,oSlider,sSingleSize,second,fSpeed,point){
var oSubLi = $id(oEventCont).getElementsByTagName('li');
var oTxtLi = $id(oTxtCont).getElementsByTagName('li');
var interval,timeout,oslideRange;
var time=1;
var speed = fSpeed
var sum = oSubLi.length;
var a=0;
var delay=second * 1000;
var setValLeft=function(s){
return function(){
oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
$id(oSlider).style[point] =-Math.floor(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
if(oslideRange==[(sSingleSize * s)]){
clearInterval(interval);
a=s;
}
}
};
var setValRight=function(s){
return function(){
oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
$id(oSlider).style[point] =-Math.ceil(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
if(oslideRange==[(sSingleSize * s)]){
clearInterval(interval);
a=s;
}
}
}
function autoGlide(){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
clearTimeout(interval);
if(a==(parseInt(sum)-1)){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
a=0;
oSubLi[a].className="active";
oTxtLi[a].className = "active";
interval = setInterval(setValLeft(a),time);
timeout = setTimeout(autoGlide,delay);
}else{
a++;
oSubLi[a].className="active";
oTxtLi[a].className = "active";
interval = setInterval(setValRight(a),time);
timeout = setTimeout(autoGlide,delay);
}
}
if(auto){timeout = setTimeout(autoGlide,delay);};
for(var i=0;i<sum;i++){
oSubLi[i].onmouseover = (function(i){
return function(){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
clearTimeout(timeout);
clearInterval(interval);
oSubLi[i].className = "active";
oTxtLi[i].className = "active";
if(Math.abs(parseInt($id(oSlider).style[point]))>[(sSingleSize * i)]){
interval = setInterval(setValLeft(i),time);
this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
}else if(Math.abs(parseInt($id(oSlider).style[point]))<[(sSingleSize * i)]){
interval = setInterval(setValRight(i),time);
this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
}
}
})(i)
}
}
}
//调用语句
glide.layerGlide(
true, //设置是否自动滚动
'iconBall', //对应索引按钮
'textBall', //标题内容文本
'show_pic', //焦点图片容器
475, //设置滚动图片位移像素
2, //设置滚动时间2秒
0.1, //设置过渡滚动速度
'left' //设置滚动方向“向左”
);
</script> 展开
var glide =new function(){
function $id(id){return document.getElementById(id);};
this.layerGlide=function(auto,oEventCont,oTxtCont,oSlider,sSingleSize,second,fSpeed,point){
var oSubLi = $id(oEventCont).getElementsByTagName('li');
var oTxtLi = $id(oTxtCont).getElementsByTagName('li');
var interval,timeout,oslideRange;
var time=1;
var speed = fSpeed
var sum = oSubLi.length;
var a=0;
var delay=second * 1000;
var setValLeft=function(s){
return function(){
oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
$id(oSlider).style[point] =-Math.floor(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
if(oslideRange==[(sSingleSize * s)]){
clearInterval(interval);
a=s;
}
}
};
var setValRight=function(s){
return function(){
oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
$id(oSlider).style[point] =-Math.ceil(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
if(oslideRange==[(sSingleSize * s)]){
clearInterval(interval);
a=s;
}
}
}
function autoGlide(){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
clearTimeout(interval);
if(a==(parseInt(sum)-1)){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
a=0;
oSubLi[a].className="active";
oTxtLi[a].className = "active";
interval = setInterval(setValLeft(a),time);
timeout = setTimeout(autoGlide,delay);
}else{
a++;
oSubLi[a].className="active";
oTxtLi[a].className = "active";
interval = setInterval(setValRight(a),time);
timeout = setTimeout(autoGlide,delay);
}
}
if(auto){timeout = setTimeout(autoGlide,delay);};
for(var i=0;i<sum;i++){
oSubLi[i].onmouseover = (function(i){
return function(){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
clearTimeout(timeout);
clearInterval(interval);
oSubLi[i].className = "active";
oTxtLi[i].className = "active";
if(Math.abs(parseInt($id(oSlider).style[point]))>[(sSingleSize * i)]){
interval = setInterval(setValLeft(i),time);
this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
}else if(Math.abs(parseInt($id(oSlider).style[point]))<[(sSingleSize * i)]){
interval = setInterval(setValRight(i),time);
this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
}
}
})(i)
}
}
}
//调用语句
glide.layerGlide(
true, //设置是否自动滚动
'iconBall', //对应索引按钮
'textBall', //标题内容文本
'show_pic', //焦点图片容器
475, //设置滚动图片位移像素
2, //设置滚动时间2秒
0.1, //设置过渡滚动速度
'left' //设置滚动方向“向左”
);
</script> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询