Javascript下落图像脚本-轻微修改(位置、距离、大小)
我有一本《飘落的图像》的剧本,但是我的图像是巨大的(这是一个讽刺页面),而不是小小的落叶、雪或其他东西。我猜是因为它们太大了,它们被推到了太右边。所以我有几个问题:Javascript下落图像脚本-轻微修改(位置、距离、大小),javascript,position,size,distance,Javascript,Position,Size,Distance,我有一本《飘落的图像》的剧本,但是我的图像是巨大的(这是一个讽刺页面),而不是小小的落叶、雪或其他东西。我猜是因为它们太大了,它们被推到了太右边。所以我有几个问题: 位置:我在脚本中的何处进行编辑以使图像更加居中?(或者离右边不远) IMG之间的距离:我总共有7张图像,并将脚本设置为加载所有7张图像。不过,它似乎在添加相同版本的副本。如何在每个图像之间增加一点距离,以便您在它们下落时能更好地看到它们?(这可能也有助于解决重复问题) 大小:对于移动设备,我需要将拍摄的图像缩小。如何将此脚本中的
/*
* Falling/Rising - by John Davenport Scheuer - aka:jscheuer1
* Very freely adapted from - Autumn leaves - by Kurt Grigg (kurt.grigg@virgin.net)
* Visit http://www.dynamicdrive.com for TOS.
* Modified by jscheuer1 in http://www.dynamicdrive.com/forums
* This credit must remain for legal use.
*/
fall.dir=1; // Set 'falling' direction (1 for down, -1 for up).
fall.speed=60; // 20 to whatever (70 is pretty slow), higher numbers are slower
fall.amount=7; // Set max number of images to fall at once, the smaller the images, the higher this can be.
fall.sway=10; // Set amount of left/right swaying of objects (default=10), higher numbers produce more sway.
fall.limit=0; // Set number of fallings/risings until effect should end, use 0 for no end.
fall.target='_new'; // Set target for links
fall.click="return true;" //set onclick function for linked images
// Pre-load your image(s) below!
if(document.images){ // <-- Do Not Edit or remove this line!!!
fall.grphcs=[];
fall.hrefs=[];
fall.image0=new Image();
fall.image0.src=fall.grphcs[0]="http://whatever.com/test/assets/1.png";
fall.hrefs[0] = '';
fall.image1=new Image();
fall.image1.src=fall.grphcs[1]="http://whatever.com/test/assets/2.png";
fall.hrefs[1] = '';
fall.image2=new Image();
fall.image2.src=fall.grphcs[2]="http://whatever.com/test/assets/3.png";
fall.hrefs[2] = '';
fall.image3=new Image();
fall.image3.src=fall.grphcs[3]="http://whatever.com/test/assets/4.png";
fall.hrefs[3] = '';
fall.image4=new Image();
fall.image4.src=fall.grphcs[4]="http://whatever.com/test/assets/5.png";
fall.hrefs[4] = '';
fall.image5=new Image();
fall.image5.src=fall.grphcs[5]="http://whatever.com/test/assets/6.png";
fall.hrefs[5] = '';
fall.image6=new Image();
fall.image6.src=fall.grphcs[6]="http://whatever.com/test/assets/7.png";
fall.hrefs[6] = '';
//////////////// Stop Editing //////////////
}
fall.prepare=function(){
fall.di=document.getElementById;
fall.da=document.all;
if (!document.images||(!fall.di&&!fall.da))
return;
fall.iebod=function(){
return (document.compatMode && document.compatMode.indexOf('CSS')!=-1)? document.documentElement : document.body;
}
fall.get=function(id){return fall.di? document.getElementById(id) : fall.da[id];};
fall.t1=fall.iebod().scrollWidth;
document.write('<a href="'+fall.hrefs[0]+'" target="'+fall.target+'" onclick="'+fall.click+'"><img id="fall_test" src="'+fall.grphcs[0]+'" style="border-width:0;position:fixed!important;position:absolute;top:-2000px;left:80000px"></a>');
fall.t2=fall.iebod().scrollWidth;
if(fall.t2>fall.t1)
fall.overflows=true;
fall.get('fall_test').style.left='-2000px';
fall.zero=(fall.di&&fall.get('fall_test').style.position=='fixed')||(document.defaultView&&document.defaultView.getComputedStyle(fall.get('fall_test'), null).getPropertyValue('position')=='fixed');
if(fall.get('fall_test').parentNode&&document.createElement)
fall.get('fall_test').parentNode.removeChild(fall.get('fall_test'));
fall.Ypos=new Array();
fall.Xpos=new Array();
fall.Speed=new Array();
fall.Step=new Array();
fall.Cstep=new Array();
fall.speed=Math.max(20, fall.speed);
fall.set_ims();
}
fall.set_ims=function(){
if(fall.overflows||!fall.zero)
document.write('<div id="fall0" style="position:fixed!important;overflow:hidden;position:absolute;">');
for (fall.i = 0; fall.i < fall.amount; fall.i++){
fall.P=Math.floor(Math.random()*fall.grphcs.length);
document.write('<a href="'+fall.hrefs[fall.P]+'" target="'+fall.target+'" onclick="'+fall.click+'"><img alt="" id="si'+fall.i+'" onload="fall.fall_start();" src="'+fall.grphcs[fall.P]+'" style="border-width:0;position:fixed!important;position:absolute;top:-2000px;left:-2000px"></a>');
}
if(fall.overflows||!fall.zero)
document.write('<\/div>');
fall.WinHeight=function(){return window.innerHeight?window.innerHeight:fall.iebod().clientHeight;};
fall.WinWidth=function(){
if(window.innerWidth&&fall.iebod().clientWidth)
return Math.min(window.innerWidth,fall.iebod().clientWidth);
return window.innerWidth?window.innerWidth:fall.iebod().clientWidth;
}
for (fall.i=0; fall.i < fall.amount; fall.i++){
fall.Ypos[fall.i] = Math.round(Math.random()*fall.WinHeight());
fall.Xpos[fall.i] = Math.round(Math.random()*fall.WinWidth());
fall.Speed[fall.i]= (Math.random()*5+3)*fall.dir;
fall.Cstep[fall.i]=0;
fall.Step[fall.i]=Math.random()*0.1+0.05;
}
}
fall.falls=0;
function fall(){
var fac, cont=0, s='style', d='display', f=fall.dir, w=fall.WinWidth, h=fall.WinHeight;
var hscrll=fall.zero?0:typeof window.pageYOffset=='number'?window.pageYOffset:fall.iebod().scrollTop?fall.iebod().scrollTop:0;
var wscrll=fall.zero?0:typeof window.pageXOffset=='number'?window.pageXOffset:fall.iebod().scrollLeft?fall.iebod().scrollLeft:0;
for (var i=0; i < fall.amount; i++){
if(fall.overflows||!fall.zero){
var sc = fall.get('fall0');
sc[s].top=hscrll+'px';
sc[s].left=wscrll+'px';
sc[s].width=w()+'px';
sc[s].height=h()+'px';
}
var sy = fall.Speed[i]*Math.sin(90*Math.PI/180);
var sx = fall.Speed[i]*Math.cos(fall.Cstep[i]);
fall.Ypos[i]+=sy;
fall.Xpos[i]+=sx*fall.sway*0.1;
fac=fall.get('si'+i).offsetHeight;
if (fall.Ypos[i] > h()&&f>0||fall.Ypos[i] < fac*-1 && f<0){
fall.Xpos[i]=Math.round(Math.random()*w());
fall.Speed[i]=(Math.random()*5+3)*f;
}
if(i==fall.amount-1&&(fall.Ypos[i] > h()&&f>0||fall.Ypos[i] < fac*-1 && f<0))
fall.falls++;
fall.Ypos[i]=(fall.Ypos[i] > h()&&f>0)? fac*-1 : (fall.Ypos[i] < fac*-1 && f<0)? h()+fac : fall.Ypos[i];
if(fall.limit&&fall.falls>fall.limit&&((f>0&&fall.Ypos[i]==fac*-1)||(f<0&&fall.Ypos[i]==h()+fac)))
fall.get('si'+i)[s][d]='none';
fall.df=fall.da&&!fall.di||window.opera&&(typeof opera.version=='undefined'||opera.version()<9)? (f<0?fac*2:fac):0;
fall.get('si'+i)[s].left=fall.df? Math.min(fall.Xpos[i], w()-fall.get('si'+i).offsetWidth)+'px' : fall.Xpos[i]+'px';
fall.get('si'+i)[s].top=fall.Ypos[i]-fall.df+'px';
for (var j = 0; j < fall.amount; j++)
if (fall.get('si'+j)[s][d]!='none')
cont=1;
if(!cont){
clearInterval(fall.fall);
if(fall.overflows||!fall.zero)
sc[s][d]='none';
}
fall.Cstep[i]+=fall.Step[i];
}
}
fall.starting=1;
fall.fall_start=function(){
if (fall.started||fall.amount>fall.starting++)
return;
fall.started=true;
fall.fall=setInterval('fall()', fall.speed);
};
fall.prepare();
/*
*下降/上升-作者:约翰·达文波特·谢尔-又名:jscheuer1
*非常自由地改编自Kurt Grigg(Kurt。grigg@virgin.net)
*拜访http://www.dynamicdrive.com 对于TOS。
*在中由jscheuer1修改http://www.dynamicdrive.com/forums
*此信用证必须保留以供合法使用。
*/
fall.dir=1;//设置“下降”方向(1表示下降,1表示上升)。
下降速度=60;//20比20(70相当慢),数字越高速度越慢
下降。金额=7;//将最大图像数设置为一次下降,图像越小,下降的幅度越大。
下降。摇摆=10;//设置对象的左/右摆动量(默认值为10),数值越大,摆动越大。
fall.limit=0;//设置下降/上升次数,直到效果结束,使用0表示无结束。
fall.target=''u new';//为链接设置目标
fall.click=“return true;”//为链接图像设置onclick函数
//预加载下面的图像!
if(document.images){//fall.t1)
fall.overflows=true;
fall.get('fall_test').style.left='-2000px';
fall.zero=(fall.di&&fall.get('fall_测试').style.position='fixed')|(document.defaultView&&document.defaultView.getComputedStyle(fall.get('fall_测试'),null)。getPropertyValue('position')='fixed');
if(fall.get('fall_test').parentNode&&document.createElement)
fall.get('fall_测试').parentNode.removeChild(fall.get('fall_测试'));
Ypos=新数组();
Xpos=newarray();
fall.Speed=新数组();
fall.Step=新数组();
fall.Cstep=新数组();
下降速度=数学最大值(20,下降速度);
fall.set_ims();
}
fall.set_ims=函数(){
if(fall.overflows | | |!fall.zero)
文件。写(“”);
for(fall.i=0;fall.i 如果(fall.Ypos[i]>h()&f>0 | | fall.Ypos[i]0 | | fall.Ypos[i]0)fac*-1:(fall.Ypos[i]0和&fall.Ypos[i]=fac*-1)| |(fDoes评论给这一个提示?&lol)