div+css+js實現(xiàn)無縫滾動類似marquee無縫滾動兼容firefox
更新時間:2013年08月29日 18:02:57 作者:
marquee無縫滾動想必大家都有見過,本文利用div+css+javascript也實現(xiàn)下類似的滾動且兼容firefox,喜歡的朋友可以參考下
div+css+javascript 實現(xiàn)無縫滾動,marquee無縫滾動,無縫滾動,兼容firefox
用marquee實現(xiàn)首尾相連循環(huán)滾動效果(僅IE):
<marquee behavior="scroll" contenteditable="true" onstart="this.firstChild.innerHTML+=this.firstChild.innerHTML;" scrollamount="3" width="100" onmouseover="this.stop();" onmouseout="this.start();">
這里是要滾動的內(nèi)容
</marquee>
用div+css+javascript實現(xiàn)首尾相連循環(huán)滾動效果(兼容firefox):
<!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>
<title>div+css+javascript 實現(xiàn)無縫滾動,marquee無縫滾動,無縫滾動,兼容firefox</title>
<style type="text/css">
#scrollobj {
white-space: nowrap;
overflow: hidden;
width: 500px;
}
</style>
</head>
<body>
<div id="scrollobj" onmouseover="javascript:_stop();" onmouseout="javascript:_start();">
這里是要滾動的內(nèi)容
</div>
<script language="javascript" type="text/javascript">
<!--
function scroll(obj) {
/*往左*/
var tmp = (obj.scrollLeft)++;
//當(dāng)滾動條到達右邊頂端時
if (obj.scrollLeft == tmp) {
obj.innerHTML += obj.innerHTML;
}
//當(dāng)滾動條滾動了初始內(nèi)容的寬度時滾動條回到最左端
if (obj.scrollLeft >= obj.firstChild.offsetWidth) {
obj.scrollLeft = 0;
}
/*往上*/
//var tmp = (obj.scrollTop)++;
//if (obj.scrollTop == tmp) {
// obj.innerHTML += obj.innerHTML;
//}
//if (obj.scrollTop >= obj.firstChild.offsetWidth) {
// obj.scrollTop = 0;
//}
}
var _timer = setInterval("scroll(document.getElementById('scrollobj'))", 20);
function _stop() {
if (_timer != null) {
clearInterval(_timer);
}
}
function _start() {
_timer = setInterval("_scroll(document.getElementById('scrollobj'))", 20);
}
//-->
</script>
</body>
</html>
用marquee實現(xiàn)首尾相連循環(huán)滾動效果(僅IE):
復(fù)制代碼 代碼如下:
<marquee behavior="scroll" contenteditable="true" onstart="this.firstChild.innerHTML+=this.firstChild.innerHTML;" scrollamount="3" width="100" onmouseover="this.stop();" onmouseout="this.start();">
這里是要滾動的內(nèi)容
</marquee>
用div+css+javascript實現(xiàn)首尾相連循環(huán)滾動效果(兼容firefox):
復(fù)制代碼 代碼如下:
<!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>
<title>div+css+javascript 實現(xiàn)無縫滾動,marquee無縫滾動,無縫滾動,兼容firefox</title>
<style type="text/css">
#scrollobj {
white-space: nowrap;
overflow: hidden;
width: 500px;
}
</style>
</head>
<body>
<div id="scrollobj" onmouseover="javascript:_stop();" onmouseout="javascript:_start();">
這里是要滾動的內(nèi)容
</div>
<script language="javascript" type="text/javascript">
<!--
function scroll(obj) {
/*往左*/
var tmp = (obj.scrollLeft)++;
//當(dāng)滾動條到達右邊頂端時
if (obj.scrollLeft == tmp) {
obj.innerHTML += obj.innerHTML;
}
//當(dāng)滾動條滾動了初始內(nèi)容的寬度時滾動條回到最左端
if (obj.scrollLeft >= obj.firstChild.offsetWidth) {
obj.scrollLeft = 0;
}
/*往上*/
//var tmp = (obj.scrollTop)++;
//if (obj.scrollTop == tmp) {
// obj.innerHTML += obj.innerHTML;
//}
//if (obj.scrollTop >= obj.firstChild.offsetWidth) {
// obj.scrollTop = 0;
//}
}
var _timer = setInterval("scroll(document.getElementById('scrollobj'))", 20);
function _stop() {
if (_timer != null) {
clearInterval(_timer);
}
}
function _start() {
_timer = setInterval("_scroll(document.getElementById('scrollobj'))", 20);
}
//-->
</script>
</body>
</html>
相關(guān)文章
JavaScript+TypeScript實現(xiàn)并發(fā)隊列的示例
本文主要介紹了JavaScript+TypeScript實現(xiàn)并發(fā)隊列的示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08
用JavaScript實現(xiàn) 鐵甲無敵獎門人 “開口中”猜數(shù)游戲
JavaScript在常人看來都是門出不了廳堂的小語言,僅管它沒有明星語言的閃耀,但至少網(wǎng)頁的閃耀還是需要它的,同時它是一門很實用的語言。2009-10-10
JS面向?qū)ο缶幊袒A(chǔ)篇(二) 封裝操作實例詳解
這篇文章主要介紹了JS面向?qū)ο缶幊谭庋b操作,結(jié)合實例形式詳細分析了JS面向?qū)ο蠓庋b操作的相關(guān)概念、原理、使用方法與操作注意事項,需要的朋友可以參考下2020-03-03
JS中typeof與instanceof之間的區(qū)別總結(jié)
本文是對JS中typeof與instanceof之間的區(qū)別進行了詳細的總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11

