JavaShuo
欄目
標籤
JS不間斷無縫滾動 (兼容火狐和IE)
時間 2020-04-23
標籤
不間斷
無縫
滾動
兼容
火狐
欄目
JavaScript
简体版
原文
原文鏈接
Html代碼
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"
/>
<
title
>
向上下左右不間斷無縫滾動圖片的效果(兼容火狐和IE)/title
>
</
head
>
<
body
>
<
div
id
=
"colee"
style
=
"overflow:hidden;height:253px;width:410px;"
>
<
div
id
=
"colee1"
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
div
>
<
div
id
=
"colee2"
>
</
div
>
</
div
>
<
script
>
var
speed
=
30
;
var
colee2
=
document
.getElementById("colee2");
var
colee1
=
document
.getElementById("colee1");
var
colee
=
document
.getElementById("colee");
colee2.innerHTML
=
colee1
.innerHTML; //克隆colee1爲colee2
function Marquee1(){
//當滾動至colee1與colee2交界時
if(colee2.offsetTop-colee.scrollTop
<
=0){
colee.scrollTop-
=
colee1
.offsetHeight; //colee跳到最頂端
}else{
colee.scrollTop++
}
}
var
MyMar1
=
setInterval
(Marquee1,speed)//設置定時器
//鼠標移上時清除定時器達到滾動中止的目的
colee.onmouseover
=
function
() {clearInterval(MyMar1)}
//鼠標移開時重設定時器
colee.onmouseout
=
function
(){
MyMar1
=
setInterval
(Marquee1,speed)}
</
script
>
<!--向上滾動代碼結束-->
<
br
>
<!--下面是向下滾動代碼-->
<
div
id
=
"colee_bottom"
style
=
"overflow:hidden;height:253px;width:410px;"
>
<
div
id
=
"colee_bottom1"
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
div
>
<
div
id
=
"colee_bottom2"
>
</
div
>
</
div
>
<
script
>
var
speed
=
30
var
colee_bottom2
=
document
.getElementById("colee_bottom2");
var
colee_bottom1
=
document
.getElementById("colee_bottom1");
var
colee_bottom
=
document
.getElementById("colee_bottom");
colee_bottom2.innerHTML
=
colee_bottom1
.innerHTML
colee_bottom
colee_bottom.scrollTop
=colee_bottom.scrollHeight
function Marquee2(){
if(colee_bottom1.offsetTop-colee_bottom.scrollTop
>
=0)
colee_bottom.scrollTop+=colee_bottom2.offsetHeight
else{
colee_bottom.scrollTop--
}
}
var
MyMar2
=
setInterval
(Marquee2,speed)
colee_bottom.onmouseover
=
function
() {clearInterval(MyMar2)}
colee_bottom.onmouseout
=
function
() {
MyMar2
=
setInterval
(Marquee2,speed)}
</
script
>
<!--向下滾動代碼結束-->
<
br
>
<!--下面是向左滾動代碼-->
<
div
id
=
"colee_left"
style
=
"overflow:hidden;width:500px;"
>
<
table
cellpadding
=
"0"
cellspacing
=
"0"
border
=
"0"
>
<
tr
>
<
td
id
=
"colee_left1"
valign
=
"top"
align
=
"center"
>
<
table
cellpadding
=
"2"
cellspacing
=
"0"
border
=
"0"
>
<
tr
align
=
"center"
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
</
tr
>
</
table
>
</
td
>
<
td
id
=
"colee_left2"
valign
=
"top"
>
</
td
>
</
tr
>
</
table
>
</
div
>
<
script
>
<!--oyzd-->
//使用div時,請保證colee_left2與colee_left1是在同一行上.
var
speed
=
30
//速度數值越大速度越慢
var
colee_left2
=
document
.getElementById("colee_left2");
var
colee_left1
=
document
.getElementById("colee_left1");
var
colee_left
=
document
.getElementById("colee_left");
colee_left2.innerHTML
=
colee_left1
.innerHTML
function Marquee3(){
if(colee_left2.offsetWidth-colee_left.scrollLeft
<
=0)//offsetWidth 是對象的可見寬度
colee_left.scrollLeft-
=
colee_left1
.offsetWidth//scrollWidth 是對象的實際內容的寬,不包邊線寬度
else{
colee_left.scrollLeft++
}
}
var
MyMar3
=
setInterval
(Marquee3,speed)
colee_left.onmouseover
=
function
() {clearInterval(MyMar3)}
colee_left.onmouseout
=
function
() {
MyMar3
=
setInterval
(Marquee3,speed)}
</
script
>
<!--向左滾動代碼結束-->
<
br
>
<!--下面是向右滾動代碼-->
<
div
id
=
"colee_right"
style
=
"overflow:hidden;width:500px;"
>
<
table
cellpadding
=
"0"
cellspacing
=
"0"
border
=
"0"
>
<
tr
>
<
td
id
=
"colee_right1"
valign
=
"top"
align
=
"center"
>
<
table
cellpadding
=
"2"
cellspacing
=
"0"
border
=
"0"
>
<
tr
align
=
"center"
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
<
td
>
<
p
>
<
img
src
=
"oyzd.img"
>
</
p
>
</
td
>
</
tr
>
</
table
>
</
td
>
<
td
id
=
"colee_right2"
valign
=
"top"
>
</
td
>
</
tr
>
</
table
>
</
div
>
<
script
>
var
speed
=
30
//速度數值越大速度越慢
var
colee_right2
=
document
.getElementById("colee_right2");
var
colee_right1
=
document
.getElementById("colee_right1");
var
colee_right
=
document
.getElementById("colee_right");
colee_right2.innerHTML
=
colee_right1
.innerHTML
function Marquee4(){
if(colee_right.scrollLeft
<
=0)
colee_right.scrollLeft+=colee_right2.offsetWidth
else{
colee_right.scrollLeft--
}
}
var
MyMar4
=
setInterval
(Marquee4,speed)
colee_right.onmouseover
=
function
() {clearInterval(MyMar4)}
colee_right.onmouseout
=
function
() {
MyMar4
=
setInterval
(Marquee4,speed)}
</
script
>
<!--向右滾動代碼結束-->
</
body
>
</
html
>
相關文章
1.
ie 火狐兼容集錦
2.
IE和火狐兼整理
3.
js無縫滾動
4.
JS在IE下兼容,而在火狐下不兼容的技巧小結
5.
JavaScript自定義瀏覽器滾動條兼容IE、 火狐和chrome
6.
js文字無縫滾動
7.
div內容滾動,無縫滾動
8.
Javascript的IE和Firefox(火狐)兼容性 css
9.
js代碼激發onchange事件,兼容谷歌火狐IE
10.
js控制點擊事件冒泡,兼容ie火狐蘋果
更多相關文章...
•
ionic 滾動條
-
ionic 教程
•
CIDR(無類域間路由)是什麼?
-
TCP/IP教程
•
SpringBoot中properties文件不能自動提示解決方法
•
IntelliJ IDEA中SpringBoot properties文件不能自動提示問題解決
相關標籤/搜索
ie兼容性
火狐
不兼容性
不兼容
兼容
無間斷
無縫
水火不容
不間斷
滾動
Firefox
JavaScript
XLink 和 XPointer 教程
Docker教程
Docker命令大全
0
分享到微博
分享到微信
分享到QQ
每日一句
每一个你不满意的现在,都有一个你没有努力的曾经。
最新文章
1.
JDK JRE JVM,JDK卸載與安裝
2.
Unity NavMeshComponents 學習小結
3.
Unity技術分享連載(64)|Shader Variant Collection|Material.SetPassFast
4.
爲什麼那麼多人用「ji32k7au4a83」作密碼?
5.
關於Vigenere爆0總結
6.
圖論算法之最小生成樹(Krim、Kruskal)
7.
最小生成樹 簡單入門
8.
POJ 3165 Traveling Trio 筆記
9.
你的快遞最遠去到哪裏呢
10.
雲徙探險中臺賽道:借道雲原生,尋找「最優路線」
本站公眾號
歡迎關注本站公眾號,獲取更多信息
相關文章
1.
ie 火狐兼容集錦
2.
IE和火狐兼整理
3.
js無縫滾動
4.
JS在IE下兼容,而在火狐下不兼容的技巧小結
5.
JavaScript自定義瀏覽器滾動條兼容IE、 火狐和chrome
6.
js文字無縫滾動
7.
div內容滾動,無縫滾動
8.
Javascript的IE和Firefox(火狐)兼容性 css
9.
js代碼激發onchange事件,兼容谷歌火狐IE
10.
js控制點擊事件冒泡,兼容ie火狐蘋果
>>更多相關文章<<