找了一个在JSP页面滚动播放新闻的JS方法感觉不错。
2011-08-02 09:46
886 查看
原文地址忘记了,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title> 滚动新闻类 - 51js.com - biyuan</title>
<style type="text/css">
body {
text-align:center;
}
td {
font-size:12px;
line-height:20px;
text-align:left;
}
.marquee {
width:100%;
height:100%;
overflow:hidden;
}
.m {
height:20px;
}
.m2 {
height:90px;
}
</style>
</head>
<body>
<table border='1'>
<tr>
<td height='20' width='250'><div id='marquee1' class='marquee m'></div></td>
<td height='20' width='300'><div id='marquee2' class='marquee m'></div></td>
</tr>
<tr>
<td height='99' colspan='2'>基本上够用了吧!</td>
</tr>
<tr>
<td height='90' colspan='2'><div id='marquee3' class='marquee m2'></div></td>
</tr>
</table>
<script language="JavaScript">
function BYMarquee(){
this.Content = []; //显示内容
this.Speed = 20; //上移速度
this.Object = {}; //marquee容器对象
this.Pause = true; //是否停留
this.Start = function(){
var o = this.Object;
var Pause = this.Pause;
var Stop = false;
var Stop2 = false;
o.onmouseover = function(){
Stop = Stop2 = true;
}
o.onmouseout = function(){
Stop = Stop2 = false;
}
var BodyHtml = [];
for(var i in this.Content){
BodyHtml.push("<a href=\"" + this.Content[i].link + "\">" + this.Content[i].text + "</a>");
}
var Dv = document.createElement("div");
Dv.innerHTML = BodyHtml.join("<br />");
o.appendChild(Dv);
var DvHeight = Dv.offsetHeight;
while(Dv.offsetHeight / 2 < o.offsetHeight){
Dv.innerHTML += "<br />" + Dv.innerHTML;
}
Dv.innerHTML += "<br />" + Dv.innerHTML;
setInterval(function(){
if(!Stop){
o.scrollTop ++;
if(o.scrollTop == o.scrollHeight - o.offsetHeight){
o.scrollTop = DvHeight - o.offsetHeight;
}
if(Pause){
if(o.scrollTop % o.offsetHeight == 0){
Stop = true;
setTimeout(function(){
Stop = Stop2;
}, 3000);
}
}
}
}, this.Speed);
}
}
//实例1
var marquee1 = new BYMarquee();
marquee1.Content = [
{link : '#', text : '英法国防部证实两国核潜艇相撞'},
{link : '#', text : '中国赴欧采购清单敲定 涉及金额150亿元'}
];
marquee1.Object = document.getElementById('marquee1');
marquee1.Start();
//实例2
var marquee2 = new BYMarquee();
marquee2.Content = [
{link : '#', text : '剑仙李横握锋利嚣张的地铜剑,左右晃动'},
{link : '#', text : '你的奴隶【剑仙李】奋起反抗,被你狠狠地教训了一顿!'},
{link : '#', text : '我的奴隶 Su.新武将 在奴隶市场输给了 金光灿烂'}
];
marquee2.Speed = 10;
marquee2.Object = document.getElementById('marquee2');
marquee2.Start();
//实例3
var marquee3 = new BYMarquee();
marquee3.Content = [
{link : '#', text : '关于封装的方法之间调用的问题求助'},
{link : '#', text : '如何用Javascript来删除浏览器的历史记录?'},
{link : '#', text : '请高手帮忙破解一段代码'}
];
marquee3.Speed = 50;
marquee3.Pause = false;
marquee3.Object = document.getElementById('marquee3');
marquee3.Start();
//销毁
marquee1 = marquee2 = marquee3 = null;
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title> 滚动新闻类 - 51js.com - biyuan</title>
<style type="text/css">
body {
text-align:center;
}
td {
font-size:12px;
line-height:20px;
text-align:left;
}
.marquee {
width:100%;
height:100%;
overflow:hidden;
}
.m {
height:20px;
}
.m2 {
height:90px;
}
</style>
</head>
<body>
<table border='1'>
<tr>
<td height='20' width='250'><div id='marquee1' class='marquee m'></div></td>
<td height='20' width='300'><div id='marquee2' class='marquee m'></div></td>
</tr>
<tr>
<td height='99' colspan='2'>基本上够用了吧!</td>
</tr>
<tr>
<td height='90' colspan='2'><div id='marquee3' class='marquee m2'></div></td>
</tr>
</table>
<script language="JavaScript">
function BYMarquee(){
this.Content = []; //显示内容
this.Speed = 20; //上移速度
this.Object = {}; //marquee容器对象
this.Pause = true; //是否停留
this.Start = function(){
var o = this.Object;
var Pause = this.Pause;
var Stop = false;
var Stop2 = false;
o.onmouseover = function(){
Stop = Stop2 = true;
}
o.onmouseout = function(){
Stop = Stop2 = false;
}
var BodyHtml = [];
for(var i in this.Content){
BodyHtml.push("<a href=\"" + this.Content[i].link + "\">" + this.Content[i].text + "</a>");
}
var Dv = document.createElement("div");
Dv.innerHTML = BodyHtml.join("<br />");
o.appendChild(Dv);
var DvHeight = Dv.offsetHeight;
while(Dv.offsetHeight / 2 < o.offsetHeight){
Dv.innerHTML += "<br />" + Dv.innerHTML;
}
Dv.innerHTML += "<br />" + Dv.innerHTML;
setInterval(function(){
if(!Stop){
o.scrollTop ++;
if(o.scrollTop == o.scrollHeight - o.offsetHeight){
o.scrollTop = DvHeight - o.offsetHeight;
}
if(Pause){
if(o.scrollTop % o.offsetHeight == 0){
Stop = true;
setTimeout(function(){
Stop = Stop2;
}, 3000);
}
}
}
}, this.Speed);
}
}
//实例1
var marquee1 = new BYMarquee();
marquee1.Content = [
{link : '#', text : '英法国防部证实两国核潜艇相撞'},
{link : '#', text : '中国赴欧采购清单敲定 涉及金额150亿元'}
];
marquee1.Object = document.getElementById('marquee1');
marquee1.Start();
//实例2
var marquee2 = new BYMarquee();
marquee2.Content = [
{link : '#', text : '剑仙李横握锋利嚣张的地铜剑,左右晃动'},
{link : '#', text : '你的奴隶【剑仙李】奋起反抗,被你狠狠地教训了一顿!'},
{link : '#', text : '我的奴隶 Su.新武将 在奴隶市场输给了 金光灿烂'}
];
marquee2.Speed = 10;
marquee2.Object = document.getElementById('marquee2');
marquee2.Start();
//实例3
var marquee3 = new BYMarquee();
marquee3.Content = [
{link : '#', text : '关于封装的方法之间调用的问题求助'},
{link : '#', text : '如何用Javascript来删除浏览器的历史记录?'},
{link : '#', text : '请高手帮忙破解一段代码'}
];
marquee3.Speed = 50;
marquee3.Pause = false;
marquee3.Object = document.getElementById('marquee3');
marquee3.Start();
//销毁
marquee1 = marquee2 = marquee3 = null;
</script>
</body>
</html>
相关文章推荐
- 多个jsp页面共享一个js对象的超级方法
- 多种方法实现当jsp页面完全加载完成后执行一个js函数
- 多个jsp页面共享一个js对象的超级方法
- 当jsp页面完全加载完成后执行一个js函数 .
- js传汉字在UTF-8标准的JSP页面中乱码的解决方法
- 一个Jsp页面导入另外一个Jsp页面的方法
- js实现分享到随页面滚动而滑动效果的方法
- 使用Django向网页的页面js中传递一个数组的方法
- JS中的中文在jsp页面中乱码的解决方法
- Jsp页面中判断字符串是否包含另一个字符串的两种方法,js判断包含的indexOf()方法
- 一个JSP页面导致的tomcat内存溢出的解决方法
- 一个不错的js html页面倒计时可精确到秒
- Struts2 访问Action和Jsp页面出现的路径问题解决方案之 ---- 为jsp、图片、js、css等获取Web工程的绝对路径的方法
- 一个jsp中用esayui dialog 弹出另一个jsp,并操作另一个jsp中js的变量和方法
- 同一个页面里的JS怎样获取jsp从别的页面获取的参数
- 多种方法实现当jsp页面完全加载完成后执行一个js函数
- 在一个页面文件中(JSP 或者HTML)使用href 跳转另一个页面时使用Js中获取传递过来的参数
- 多个jsp页面共享一个js对象
- common.js中写方法,引入jsp页面的两种方式
- js 点击一个链接后变色,但在点击页面其它链接不变色(方法一)