js 无缝滚动效果学习

<!DOCTYPE html>
<html>
<head>
    <title>无缝滚动测试</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script type="text/javascript" src="../dist/zepto.js"></script>
</head>
<body>
<style type="text/css">
    #ScrollContainer{
        overflow: hidden;
        width: 500px;
    }
    #Container{
        float: left;
        width: 800%;
    }
    #detail{
        float: left;
    }
    #detailview{
        float: left;
    }
</style>
<div id="ScrollContainer">
    <div id="Container">
        <div id="detail">
            <a href="#"><img src="http://www.codefans.net//jscss/demoimg/wall_s1.jpg" border="0" /></a>
            <a href="#"><img src="http://www.codefans.net//jscss/demoimg/wall_s2.jpg" border="0" /></a>
            <a href="#"><img src="http://www.codefans.net//jscss/demoimg/wall_s3.jpg" border="0" /></a>
            <a href="#"><img src="http://www.codefans.net//jscss/demoimg/wall_s4.jpg" border="0" /></a>
            <a href="#"><img src="http://www.codefans.net//jscss/demoimg/wall_s5.jpg" border="0" /></a>
            <a href="#"><img src="http://www.codefans.net//jscss/demoimg/wall_s6.jpg" border="0" /></a>
        </div>
        <div id="detailview"></div>
    </div>
</div>
<script>
    (function(Scroll,Container,detail){

        //nowmyMarquee.run();

    })("ScrollContainer","Container","detail")

    function myMarquee(Scroll,Container,detail){
        console.log(this);
        var that=this;
        this.speed=10;
        this.tabScroll=document.getElementById(Scroll);
        this.tabdetail=document.getElementById(detail);
        this.tabdetailView=document.getElementById(detail+'view');
        this.tabdetailView.innerHTML=this.tabdetail.innerHTML;
        this.Marquee=function(){
            if(this.tabdetailView.offsetWidth-this.tabScroll.scrollLeft<=0)
            {
                //一轮滚动结束需要充值
                this.tabScroll.scrollLeft-=this.tabdetail.offsetWidth;
            }
            else
            {
                this.tabScroll.scrollLeft++;
            };

        };
        this.tabdetail.οnmοuseοver=function(){
            clearInterval(that.MyMar)
        };
        this.tabdetail.οnmοuseοut=function(){
            that.MyMar=setInterval(
                  function(){  that.Marquee.apply(that)}
                    , that.speed);

        }
        this.run=function(){
            this.MyMar=setInterval(
                    function(){  that.Marquee.apply(that)}
                    ,   that.speed);
        }
        this.run();

    }
    var  nowmyMarquee=new myMarquee("ScrollContainer","Container","detail")


</script>
</body>
</html>

offsetWidth 和 scrollLeft 的应用 和子容器800%与父容器的使用

参考 http://blog.csdn.net/xuantian868/article/details/3116442

obj.offsetWidth 指 obj 控件自身的绝对宽度,不包括因 overflow 而未显示的部分,也就是其实际占据的宽度,整型,单位像素。

3.scrollLeft,scrollTop:
如果元素是可以滚动的,可以通过这俩个属性得到元素在水平和垂直方向上滚动了多远,单位是象素.
对于不可以滚动的元素,这些值总是0.

scrollLeft 主要用来定位子容器在父容器中的定位,控制子容器的位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值