您的位置:首页 > 运维架构

无间滚动[兼容IE6-7, FF, OPERA等各种浏览器](

2008-11-24 19:48 543 查看
<IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4490194096475053&dt=1227527290984&lmt=1226285527&prev_slotnames=1891601125&output=html&slotname=3685991503&correlator=1227527290953&url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F09%2F1587.html&ea=0&ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__90.html&frm=0&ga_vid=2091876339.1227189135&ga_sid=1227527003&ga_hid=1152733197&ga_fc=true&flash=9.0.124.0&u_h=768&u_w=1024&u_ah=715&u_aw=1024&u_cd=32&u_tz=480&u_java=true&dtd=16" frameBorder=0 width=300 scrolling=no height=250 allowTransparency></IFRAME><!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" />
<title>Marquee 替代 -- 无间滚动</title>
<style type="text/css">
<!--
* {padding: 0; margin: 0}
body {margin: 3em; font: 12px Tahoma; background: #EAEAEA; color: #333333; line-height: 20px}
input, textarea {font: 12px Tahoma; color: #666666; padding: 2px; border: solid 1px #DBDBDB}
textarea {padding: 5px; line-height: 20px}
p {margin: 1em 0}
ul {}
li {height: 1%; overflow: hidden; list-style-type: none}
a {color: #666666; text-decoration: none}
a:hover {color: #333333}
.r {float: right}
.l {float: left}
.b {font-weight: bold}
.gray {color: #666666; margin-top: 8px}
.light {color:#FF6600; margin: 0 5px}
.case {display: block; padding: 0 2em 2em 2em; border: solid 1px #EAEAEA; background: #FFFFFF; margin-bottom: 2em; height: 1%; overflow: hidden}
.title {display:block; padding: .5em 2em .5em 1em; margin: 0 -2em 2em -2em; font-weight: bold; color: #000000; background: #FAFAFA; border-bottom: solid 1px #EAEAEA}
.call {display:block;}
.key {display: block; width: 8em; float: left}
.type {display: block; width: 6em; float: left}
.info {padding-left: 2em}
.demo {margin-bottom: 2em}
-->
</style>
<style type="text/css">
<!--
.MyMarqueeX {width: 98%; height: 150px; overflow: hidden; margin: 0 auto 0 auto}
.MyMarqueeX img {width: 185px; height: 125px; border: 2px solid #e6e6e6; padding: 1px; margin: 5px}
.MyMarqueeY {width: 205px; height: 420px; overflow: hidden;}
.MyMarqueeY img {width: 185px; height: 125px; border: 2px solid #e6e6e6; padding: 1px; margin: 5px}
-->
</style>
<script language="javascript" type="text/javascript">
//<!--
// 附带函数
var
// 用ID获取元素
$ = function(element) {
return typeof(element) == 'object' ? element : document.getElementById(element);
},
// 生成随机数
RandStr = function(n, u){
var tmStr = "abcdefghijklmnopqrstuvwxyz0123456789";
var Len = tmStr.length;
var Str = "";
for(i=1;i<n+1;i++){
Str += tmStr.charAt(Math.random()*Len);
}
return (u ? Str.toUpperCase() : Str);
};
//-->
</script>
<script language="javascript" type="text/javascript">
//<!--
/*******************************************
- Marquee 替代 -- 无间滚动
- By Mudoo 2008.8
- http://hi.baidu.com/mt20 ********************************************
new Marquee({
obj : 'myMarquee', // 滚动对象(必须)
name : 'MyMQ_1', // 实例名(可选,不指定则随机)
mode : 'x', // 滚动模式(可选,x=水平, y=垂直,默认x)
speed : 10, // 滚动速度(可选,越小速度越快,默认10)
autoStart : true, // 自动开始(可选,默认True)
movePause : true // 鼠标经过是否暂停(可选,默认True)
});
********************************************/
var MyMarquees = new Array();
// 获取检测实例名
function getMyMQName(mName) {
var name = mName==undefined ? RandStr(5) : mName;
var myNames = ','+ MyMarquees.join(',') +',';

while(myNames.indexOf(','+ name +',')!=-1) {
name = RandStr(5);
}
return name;
}
function Marquee(inits) {
var _o = this;
var _i = inits;

if(_i.obj==undefined) return;
_o.mode = _i.mode==undefined ? 'x' : _i.mode; // 滚动模式(x:横向, y:纵向)
_o.mName = getMyMQName(_i.name); // 实例名
_o.mObj = $(_i.obj); // 滚动对象
_o.speed = _i.speed==undefined ? 10 : _i.speed; // 滚动速度
_o.autoStart= _i.autoStart==undefined ? true : _i.autoStart;// 自动开始
_o.movePause= _i.movePause==undefined ? true : _i.movePause;// 鼠标经过是否暂停

_o.mDo = null; // 计时器
_o.pause = false; // 暂停状态

// 无间滚动初始化
_o.init = function() {
if((_o.mObj.scrollWidth<=_o.mObj.offsetWidth && _o.mode=='x') || (_o.mObj.scrollHeight<=_o.mObj.offsetHeight && _o.mode=='y')) return;

MyMarquees.push(_o.mName);

// 克隆滚动内容
_o.mObj.innerHTML = _o.mode=='x' ? (
'<table width="100%" border="0" align="left" cellpadding="0" cellspace="0">'+
' <tr>'+
' <td id="MYMQ_'+ _o.mName +'_1">'+ _o.mObj.innerHTML +'</td>'+
' <td id="MYMQ_'+ _o.mName +'_2">'+ _o.mObj.innerHTML +'</td>'+
' </tr>'+
'</table>'
) : (
'<div id="MYMQ_'+ _o.mName +'_1">'+ _o.mObj.innerHTML +'</div>'+
'<div id="MYMQ_'+ _o.mName +'_2">'+ _o.mObj.innerHTML +'</div>'
);

// 获取对象、高宽
_o.mObj1 = $('MYMQ_'+ _o.mName +'_1');
_o.mObj2 = $('MYMQ_'+ _o.mName +'_2');
_o.mo1Width = _o.mObj1.scrollWidth;
_o.mo1Height = _o.mObj1.scrollHeight;

// 初始滚动
if(_o.autoStart) _o.start();
};

// 开始滚动
_o.start = function() {
_o.mDo = setInterval((_o.mode=='x' ? _o.moveX : _o.moveY), _o.speed);
if(_o.movePause) {
_o.mObj.onmouseover = function() {_o.pause = true;}
_o.mObj.onmouseout = function() {_o.pause = false;}
}
}

// 停止滚动
_o.stop = function() {
clearInterval(_o.mDo)
_o.mObj.onmouseover = function() {}
_o.mObj.onmouseout = function() {}
}

// 水平滚动
_o.moveX = function() {
if(_o.pause) return;
var left = _o.mObj.scrollLeft;
if(left==_o.mo1Width){
_o.mObj.scrollLeft = 0 ;
}else if(left>_o.mo1Width) {
_o.mObj.scrollLeft = left-_o.mo1Width;
}else{
_o.mObj.scrollLeft++;
}
};

// 垂直滚动
_o.moveY = function() {
if(_o.pause) return;
var top = _o.mObj.scrollTop;
if(top==_o.mo1Height){
_o.mObj.scrollTop = 0 ;
}else if(top>_o.mo1Height) {
_o.mObj.scrollTop = top-_o.mo1Height;
}else{
_o.mObj.scrollTop++;
}
};

_o.init();
}
//-->
</script>
</head>
<body>
<div class="case">
<div class="title"><a href="#" class="r">Top</a>Marquee 调用方法</div>
<div class="b">new Marquee({obj, name, mode, speed, autoStart, movePause});</div>
<ul class="info gray">
<li><span class="key">obj:</span><span class="type">Object</span>滚动对象  (*必须)</li>
<li><span class="key">name:</span><span class="type">String</span>实例名  (*可选,默认随机)</li>
<li><span class="key">mode:</span><span class="type">String</span>滚动模式(x=水平, y=垂直)  (*可选,默认为x)</li>
<li><span class="key">speed:</span><span class="type">Number</span>滚动速度,越小速度越快  (*可选,默认10)</li>
<li><span class="key">autoStart:</span><span class="type">Boolean</span>自动开始  (*可选,默认True)</li>
<li><span class="key">movePause:</span><span class="type">Boolean</span>鼠标经过是否暂停  (*可选,默认True)</li>
</ul>
</div>
<div class="case">
<div class="title"><a href="#" class="r">Top</a><a name="1" ></a>Marquee 演示 - 横向模式</div>
<div id="MyMarqueeX" class="MyMarqueeX">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="http://www.fjhongyi.com/img/31.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/32.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/33.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/34.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/35.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/36.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/31.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/32.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/33.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/34.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/35.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/36.jpg" alt="魅力泉州" /></td>
</tr>
</table>
</div>
</div>
<div class="case">
<div class="title"><a href="#" class="r">Top</a><a name="1" ></a>Marquee 演示 - 纵向模式</div>
<div id="MyMarqueeY" class="MyMarqueeY">
<img src="http://www.fjhongyi.com/img/31.jpg" alt="魅力泉州" /><br />
<img src="http://www.fjhongyi.com/img/32.jpg" alt="魅力泉州" /><br />
<img src="http://www.fjhongyi.com/img/33.jpg" alt="魅力泉州" /><br />
<img src="http://www.fjhongyi.com/img/34.jpg" alt="魅力泉州" /><br />
<img src="http://www.fjhongyi.com/img/35.jpg" alt="魅力泉州" /><br />
<img src="http://www.fjhongyi.com/img/36.jpg" alt="魅力泉州" /><br />
</div>
</div>
<div class="case">
<div class="title"><a href="#" class="r">Top</a><a name="1" ></a>Marquee 演示 - 横向模式(内容不够宽)</div>
<div id="MyMarqueeX2" class="MyMarqueeX">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="http://www.fjhongyi.com/img/31.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/32.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/33.jpg" alt="魅力泉州" /></td>
<td><img src="http://www.fjhongyi.com/img/34.jpg" alt="魅力泉州" /></td>
</tr>
</table>
</div>
</div>
<div class="case">
<div class="title"><a href="#" class="r">Top</a><a name="1" ></a>Marquee 演示 - 纵向模式(内容不够长)</div>
<div id="MyMarqueeY2" class="MyMarqueeY">
<img src="http://www.fjhongyi.com/img/31.jpg" alt="魅力泉州" /><br />
<img src="http://www.fjhongyi.com/img/32.jpg" alt="魅力泉州" /><br />
</div>
</div>
<script language="javascript" type="text/javascript">
//<!--
/*********************************************
- Marquee 演示
*********************************************/
new Marquee({
obj : 'MyMarqueeX',
movePause : false
});
new Marquee({
obj : 'MyMarqueeY',
mode : 'y'
});
new Marquee({
obj : 'MyMarqueeX2',
movePause : false
});
new Marquee({
obj : 'MyMarqueeY2',
mode : 'y'
});
//-->
</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息