html新闻上下⾃动滚动代码,Htmljs轻松实现向上下左右循环滚
动代码
向上下左右不间断⽆缝滚动图⽚的效果(兼容⽕狐和IE)
var speed=30;
var ElementById("colee2");
var ElementById("colee1");
var ElementById("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++
}*/
//⽆限循环
if(colee.scrollTop>=colee1.offsetHeight){
colee.scrollTop=0;
}
else
{
colee.scrollTop++;
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//⿏标移上时清除定时器达到滚动停⽌的⽬的
colee.οnmοuseοver=function() {clearInterval(MyMar1)}
//⿏标移开时重设定时器
colee.οnmοuseοut=function(){MyMar1=setInterval(Marquee1,speed)}
var speed=30
var colee_ElementById("colee_bottom2");
var colee_ElementById("colee_bottom1");
var colee_ElementById("colee_bottom");
html滚动效果代码colee_bottom2.innerHTML=colee_bottom1.innerHTML
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.οnmοuseοver=function() {clearInterval(MyMar2)}
colee_bottom.οnmοuseοut=function() {MyMar2=setInterval(Marquee2,speed)}
//使⽤div时,请保证colee_left2与colee_left1是在同⼀⾏上.
var speed=30//速度数值越⼤速度越慢
var colee_ElementById("colee_left2");
var colee_ElementById("colee_left1");
var colee_ElementById("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.οnmοuseοver=function() {clearInterval(MyMar3)}
colee_left.οnmοuseοut=function() {MyMar3=setInterval(Marquee3,speed)}
var speed=30//速度数值越⼤速度越慢
var colee_ElementById("colee_right2");
var colee_ElementById("colee_right1");
var colee_ElementById("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.οnmοuseοver=function() {clearInterval(MyMar4)}
colee_right.οnmοuseοut=function() {MyMar4=setInterval(Marquee4,speed)}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论