站长中国
设为首页 | 站长论坛

站长论坛 站长下载
您所在的位置: 站长中国 > 站长学院 > 网页设计 > 网页特效 > 正文

JS无缝滚屏效果
  2007年09月10日05:35:06  评论(1条) 字体:[ ]
相关热点:

下面的JS代码另存为一个外部的JS文件里,在使用时,先引用该JS文件,再滚屏的HTML后添加JS脚本,声明一个JS滚屏对象就可以使用了

可实现上下左右四个方向不同的滚动效果

如另外为marquee.js

<script language="javascript" src="marquee.js"></script>
<div id="dv_Marquee">
  <table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <th scope="col"><img src="demo.jpg" width="400" height="200" /></th>
    </tr>
    <tr>
      <td><img src="demo.jpg" width="400" height="200" /></td>
    </tr>
  </table>
</div>
<script language="javascript">
    var _m = new Marquee("_m","dv_Marquee","up",1,1);//向上滚屏

</script>

dv_Marquee是一个定义了宽高,无填充,无边框,溢出设置为隐藏的一个块区域,无需要额外的marquee标记

如果横向滚动时,内容的实际宽度小于滚动区域宽度时,无滚动效果
纵向滚动与横向滚动一样

可实现四个方向的滚动方式

鼠标移上去,自动停止

鼠标移开,恢复滚动

//以下代码存储为外部JS文件

//JS模拟Marquee连续滚屏效果
//IE 6.0 测试通过
//FireFox 1.5.0.7 测试通过
//Opera 9.02 测试通过
//NetScape 8.1测试通过

//author:梦猫猫
//QQ:16991200
//Created:2006-10-18
//intro:
/*
  instance:创建的实例名称
  marquee:滚动区域容器的ID,要求无填充,无边框,overflow为hidden
  direction:滚动方向,值分别为:up,down,left,right
  delay:滚动的速度,值最小为1,值越小越快
  amount:滚动步进量,值最小为1,值越大越快
*/

 function Marquee(instance,marquee,direction,delay,amount){
  this.instance =instance;//实例名称
  this.marquee = document.getElementById(marquee);
  this.delay = delay;
  if(this.delay==null){
   this.delay = 1;
  }
  this.amount = amount;
  if(this.amount==null){
   this.amount = 1;
  }
  this.direction = direction;
  this.width = this.marquee.clientWidth;
  this.height = this.marquee.clientHeight;
  this.container = document.createElement("table");
  this.container.border=0;
  this.container.cellspacing="0"
  this.container.cellpadding="0"
  var _HTML = this.marquee.innerHTML;
  this.marquee.innerHTML = "";
  this.marquee.appendChild(this.container);
  var _tr = this.container.insertRow(this.container.rows.length);
  var _td = _tr.insertCell(_tr.cells.length);
  _td.innerHTML = _HTML;
  this.scrollHeight = this.container.clientHeight;
  this.scrollWidth = this.container.clientWidth;
  switch(this.direction.toLowerCase()){
   case "up":
   case "down":
    if(this.scrollHeight>=this.height){
     var _tr = this.container.insertRow(this.container.rows.length);
     var _td = _tr.insertCell(_tr.cells.length);
     _td.innerHTML = _HTML;
     this.scrollHeight = this.container.clientHeight;
    }
    if(this.direction.toLowerCase()=="down"){
     this.marquee.scrollTop=this.scrollHeight/2;
    }
    break;
   default:
    if(this.scrollWidth>=this.width){
     var _td = _tr.insertCell(_tr.cells.length);
     _td.innerHTML = _HTML;
     this.scrollWidth = this.container.clientWidth;
    }
    
  }
  
  this.marquee.m = this;
  
  this.intervalId = null;
  this.marquee.onmouseover = function (){
   this.m.Stop();
  }
  this.marquee.onmouseout = function (){
   this.m.Start();
  }
  this.Start();
 }
 Marquee.prototype.Start = function (){
  this.intervalId = setInterval(this.instance+".Scroll()",this.delay)
  //this.Scroll();
 }
 Marquee.prototype.Stop = function (sender){
  if(this.intervalId!=null){
   clearInterval(this.intervalId);
  }
 }
 Marquee.prototype.Scroll = function (){
  switch(this.direction.toLowerCase()){
   case "up":
    if((this.marquee.scrollTop+this.height)>=this.scrollHeight){
     this.marquee.scrollTop-=this.scrollHeight/2
    }
    if(this.scrollHeight>this.height){
     this.marquee.scrollTop+=this.amount;
    }
    break;
   case "down":
    if(this.marquee.scrollTop<=0){
     this.marquee.scrollTop+=this.scrollHeight/2
    }
    if(this.scrollHeight>this.height){
     this.marquee.scrollTop-=this.amount;
    }
    break;
   case "right":
    if(this.marquee.scrollLeft<=0){
     this.marquee.scrollLeft+=this.scrollWidth/2
    }
    if(this.scrollWidth>this.width){
     this.marquee.scrollLeft-=this.amount;
    }
    break;
   default:
    if((this.marquee.scrollLeft+this.width)>=this.scrollWidth){
     this.marquee.scrollLeft-=this.scrollWidth/2
    }
    if(this.scrollWidth>this.width){
     this.marquee.scrollLeft+=this.amount;
    }
  }
 }
//以上为外部JS代码


责任编辑:

收藏本文 打印 打印本文  推荐本文 告诉好友 投稿 投稿邮箱

站长排行

学院

新闻

专栏

盈利

[揭密网络黄链]中国留学生买凶专破日本
JSP语法(6)
超强弹出窗口代码,什么都挡不住
FLASH视觉特效实例之地震效果
贴吧发帖机使用教程(绝对原创)
关于数据分页(转自www.codeproject.co
ASP实现文件直接下载
Photoshop制作光感超酷效果水晶球
 遍历ASP.NET页面控件
永远的后门[经典]+查不出的后门
淘宝网卖家公然叫卖“艳照门”照片集
驳《百度Hi面世对腾讯有利》
Google绿色专家质疑黑色背景网页节省资
国内各IT企业办公环境揭秘(多图)
阿里妈妈广告卖主全攻略
站长创业源动力 主流站长站赏析
推荐阅读:80年小子的创业道理
Discuz!6.0猛将出击 最强论坛程序酷炫
我的网络,我的团队:专访李文明
百度新闻频道改版十天 流量止跌反弹翻
ECSHOP模板制作参考文档
悬挂阿里妈妈会否被百度惩罚
阿里妈妈是否是中小站长的救世主?
最强网店ECShop发新版 众多酷炫功能给
ECSHOP模板下载
土豆网,优酷网,爆米花等视频网站采集
DedeCms模板安装/制作概述
网上商店系统巅峰对决 ECShop vs ShopE
艰难的走在创业的路上 第一天
编程中国全站采集规则
性福联盟 一个不尊重站长的联盟
大脚:日赚100元—揭露最新firefox欺骗
大脚:垃圾站超级赚钱法之二—突破“站
大脚:垃圾站超级赚钱法之——前言
迅雷联盟、快车联盟收入对比
经理人必看的十个管理网站
Google Adsense的秘密 第二版
西联汇款兑付城市查询
不用SEO取得成功的10个步骤
关于做GOOGLE的五条经验
站长学院  网页设计 建站教程 图形图象 网络编程

Photoshop CS3
Photoshop CS3
不用Photoshop
不用Photoshop

DIV+CSS的开发方式 听听另外的
虚拟主机建站动易里快速生成的
VBScript特效代码 满屏幕乱跑
牛气!一个菜鸟站长的超强网站
创建、维护一个个人博客的“投
让网站流量稳步飙升的秘籍
网站推广的基本思想

新闻线索

如果你有站长界人事变动、重组并购、变革技术出现,以及产品投诉等重要新闻线索,请告诉我们,我们会给予特别关注。
0631-3653338
站长中国编辑部
站长中国24小时新闻热线: 13256307008