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)++;
//當滾動條到達右邊頂端時
if (obj.scrollLeft == tmp) {
obj.innerHTML += obj.innerHTML;
}
//當滾動條滾動了初始內(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):
復制代碼 代碼如下:
<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)++;
//當滾動條到達右邊頂端時
if (obj.scrollLeft == tmp) {
obj.innerHTML += obj.innerHTML;
}
//當滾動條滾動了初始內(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判斷ie瀏覽器6/7版本加載不同樣式表的實現(xiàn)代碼
ie6/ie7的兼容問題很讓人苦惱,我們可以針對這兩個版本的瀏覽器單獨寫獨立的樣式表,來解決兼容問題。這里的例子以判斷ie6與ie7來加載不同的樣式表2011-12-12小程序input數(shù)據(jù)雙向綁定實現(xiàn)方法
這篇文章主要介紹了小程序input數(shù)據(jù)雙向綁定實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10