鏡像站點 | MAP
 
網站首頁 網站策劃 優化推廣 作品展示 SEO知識 技術文獻 費用標準 聯系方式
SEO知識
技術文獻
相關文章

首頁 > 技術文獻

連續環繞滾動圖片

TIME:2009-7-6 9:39:42  HITS:

關鍵字:哈爾濱網站制作  摘自:目標科技

以下是代碼片段:

<!--把下列代碼放到HEAD區域內-->
<head>
<title>連續環繞滾動圖片</title>
<script type='text/javascript'>
function carousel(params){
  if(!(params.width>0 && isFinite(params.width)))params.width=100;
  if(!(params.height>0 && isFinite(params.height)))params.height=100;
  if(!(params.sides>2 && isFinite(params.sides)))params.sides=4;
  if(!(params.steps>0 && params.steps<100 && isFinite(params.steps)))params.steps=20;
  if(!(params.speed>0 && isFinite(params.speed)))params.speed=8;
  if(!(params.image_border_width>=0 && isFinite(params.image_border_width)))params.image_border_width=0;
  if(isFinite(params.id)||!params.id)params.id='bad_id_given_'+Math.random();
 
  document.write("<div style='position:relative;overflow:hidden;' id='"+params.id.replace(/[\r\n\t ]+/g,'_')+"'></div>");
  var cdiv=document.getElementById(params.id.replace(/[\r\n\t ]+/g,'_'))
  cdiv.style.width=params.width+'px';
  cdiv.style.height=params.height+'px';
  cdiv.style.border=params.border;
  cdiv.style.position='relative';
  cdiv.style.overflow='hidden';
  cdiv.title=params.id;
   
  var counter=0,spinning=true,interval=Math.floor(60000/params.sides/params.steps/params.speed)-5;
  interval=isNaN(interval)?200:interval;
  var img_position=[],images=[],img_dimension=[];
  var img_index=params.images.length+1,img_index_cap=2*params.images.length;
  var faces=Math.ceil(params.sides/2), dimension, direction;
  function init(){
    if(params.direction=="left" || params.direction=="right"){
      direction=params.direction;
      dimension="width";
      }
    else if(params.direction=="top" || params.direction=="bottom"){
      direction=params.direction;
      dimension="height";
      }
    else {
      direction="left";
      dimension="width";
      }     
    cdiv.style[dimension]=params[dimension]/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)+'px';
    var img=new Image();
    img.style.position='absolute';
    img.style[direction]='10000px';
    img.style.width=params.width-2*params.image_border_width+'px';
    img.style.height=params.height-2*params.image_border_width+'px';
    img.style.border=(params.image_border_width||0)+'px solid '+params.image_border_color;
  //more javascript from http://www.gm321.cn
    for(var i=0;i<params.images.length;i++){
      images[i]=img.cloneNode(true);
      images[i].src=params.images[i];
      if(params.links && params.links[i] && params.links[i]!=''){
        images[i].onclick=new Function("window.location='"+params.links[i]+"'");
        images[i].style.cursor=document.all?'hand':'pointer';
        }
      if(params.titles && params.titles[i] && params.titles[i]!='')
        images[i].title=params.titles[i];
      images[i+params.images.length]=images[i];
      if(params.images.length==faces)
        images[i+2*params.images.length]=images[i];
      cdiv.appendChild(images[i]);
      }
 
    var face_size=params.size_mode=='image'?params[dimension]:params[dimension]*Math.sin(Math.PI/params.sides);
    var face_offset=params[dimension]*Math.cos(Math.PI/params.sides)/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)/2-.5;
    var pi_piece=2*Math.PI/params.steps/params.sides;
    for(i=0;i<=params.steps*faces;i++){
      img_dimension[i]=face_size*Math.sin(pi_piece*i);
      img_position[i]=(i<params.steps*params.sides/2)?Math.floor(params[dimension]/2/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)-face_offset*Math.cos(pi_piece*i)-img_dimension[i]/2)+'px':'10000px';
      img_dimension[i]=img_dimension[i]-2*params.image_border_width>1?Math.ceil(img_dimension[i])-2*params.image_border_width+'px':'1px';
      }
    }
  init();
  cdiv.rotate = function(){
    setTimeout('document.getElementById("'+cdiv.id+'").rotate()',interval);
    if(!spinning) return;
    if(++counter>=params.steps){
      counter=0;
      if(++img_index>=img_index_cap)
        img_index=params.images.length;
      }
    images[img_index-faces].style[direction]='20000px';
    for(var i=faces-1;i>=0;i--){
      images[img_index-i].style[direction]=img_position[counter+i*params.steps];
      images[img_index-i].style[dimension]=img_dimension[counter+i*params.steps];
      }
    }
  cdiv.onmouseover=function(){
    spinning=false;
    }
  cdiv.onmouseout=function(){
    spinning=true;
    }
  setTimeout('document.getElementById("'+cdiv.id+'").rotate()',200);
  }
</script>
</head>

<!--把下列代碼放到body區域內-->
 <body>
<h3>水平方向滾動</h3>
<script type='text/javascript'>
carousel({id:'Amazon Books', //Enter arbitrary but unique ID of this slideshow instance
          border:'',
          size_mode:'image', //Enter "carousel" or "image". Affects the width and height parameters below.
          width:107, //Enter width of image or entire carousel, depending on above value
          height:140, //Enter height of image or entire carousel, depending on above value
          sides:6, //# of sides of the carousel. What's shown = sides/2. Even integer with sides/2< total images is best
          steps:23, //# of animation steps. More = smoother, but more CPU intensive
          speed:5, //Speed of slideshow. Larger = faster.
          direction:'left', //Direction of slideshow. Enter "top", "bottom", "left", or "right"
          images:['/files/pic/20050817/20058170212117530.jpg',
                  '/files/pic/20050817/20058170212137638.jpg',
                  '/files/pic/20050817/20058170212162340.jpg',
         '/files/pic/20050817/20058170212177520.jpg'],
          links: ['http://www.gm321.cn/',
         'http://www.gm321.cn/',
         'http://www.gm321.cn/',
         'http://www.gm321.cn/'],
          titles:['javascript特效',
         '網絡學院',
         '網站聯盟',
         '插件下載'],
          image_border_width:1,
          image_border_color:'blue'
          });
</script>

<h3>豎直方向滾動</h3>
<script type='text/javascript'>
carousel({id:'carousel_1', //Enter arbitrary but unique ID of this slideshow instance
          border:'',
          size_mode:'image', //Enter "carousel" or "image". Affects the width and height parameters below.
          width:107, //Enter width of image or entire carousel, depending on above value
          height:140, //Enter height of image or entire carousel, depending on above value
          sides:8, //# of sides of the carousel. What's shown = sides/2. Even integer with sides/2< total images is best
          steps:8, //# of animation steps. More = smoother, but more CPU intensive
          speed:7, //Speed of slideshow. Larger = faster.
          direction:'top', //Direction of slideshow. Enter "top", "bottom", "left", or "right"
          images:['/files/pic/20050817/20058170212117530.jpg',
                  '/files/pic/20050817/20058170212137638.jpg',
                  '/files/pic/20050817/20058170212162340.jpg',
         '/files/pic/20050817/20058170212177520.jpg'],
          links: [],
          titles:[],
          image_border_width:1,
          image_border_color:'black'
          });
</script>
</body>
               


哈爾濱目標科技開發有限公司 • 版權所有 CopyRight 2009-2012

QQ:36268333

哈爾濱網站建設熱線:13945093721 0451-88002799

mgcc电子游艺城