• 仿手机屏幕滑动效果


    因项目需要,我写了一个鼠标仿手机上的屏幕滑动的效果,本来是基于zepto.js写的(注:这是一个基于jquery的应用于手机开发的库,比jquery更小,更轻便,但jquery的很多方法,它都不支持),后来拿到jquery上试效果,发现出问题了,原来zepto.js获取一个元素的宽度的时候,把padding也算进去了,但jquery只算本身的宽度;所以出了点小问题。我把例子传上来,感兴趣的童鞋们帮忙看看,我这是初级的代码水平;

    望大家多多指点。

    注:jquery我用的是1.10.1版,没试其他版本效果怎么样。

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>焦点轮换示例</title>
    <style type="text/css">
    *{margin:0;padding:0;}
    #ad_box{position: relative; 552px; height: 140px; border: 1px solid #ccc; overflow: hidden;}
    #ads{position: absolute; top: 0; left: 0;}
    #ads li{ 136px; height:136px;list-style: none;float: left; border: 1px solid #333;}
    </style>
    <script type="text/javascript" src="../js/jquery-1.10.1.min.js"></script>
    </head>

    <body>
    <div id="ad_box">
    <ul id="ads">
    <li style="background: url(../images/9weico114.png) no-repeat center center;" title="1111111"></li>
    <li style="background: url(../images/9weico114.png) no-repeat center center;"></li>
    <li style="background: url(../images/9weico114.png) no-repeat center center;"></li>
    <li style="background: url(../images/9weico114.png) no-repeat center center;"></li>
    <li style="background:url(../images/91.jpg) no-repeat center center" title="222"></li>
    <li style="background: url(../images/aiqiyi114.png) no-repeat center center" title="333"></li>
    <li style="background: url(../images/alipay-zt.png) no-repeat center center" title="444"></li>
    <li style="background: url(../images/dianshixinwen114.jpg) no-repeat center center" title="555"></li>
    <li style="background: url(../images/fushi114.png) no-repeat center center" title="666"></li>
    <li style="background: url(../images/9weico114.png) no-repeat center center;"></li>
    <li style="background: url(../images/hangban114.png) no-repeat center center" title="777"></li>
    <li style="background: url(../images/jianfei114.png) no-repeat center center" title="888"></li>
    <li style="background: url(../images/jinshan114.png) no-repeat center center" title="999"></li>
    <li style="background: url(../images/jumeiyoupin114.png) no-repeat center center" title="1010"></li>
    <li style="background: url(../images/qingnian114.png) no-repeat center center" title="1111"></li>
    <li style="background: url(../images/qiyi114.png) no-repeat center center" title="1212"></li>
    <li style="background: url(../images/9weico114.png) no-repeat center center;"></li>
    <li style="background: url(../images/dianshixinwen114.jpg) no-repeat center center" title="555"></li>
    <li style="background: url(../images/fushi114.png) no-repeat center center" title="666"></li>
    <li style="background: url(../images/alipay-zt.png) no-repeat center center" title="444"></li>
    <li style="background: url(../images/hangban114.png) no-repeat center center" title="777"></li>
    <li style="background:url(../images/91.jpg) no-repeat center center" title="222"></li>
    <li style="background: url(../images/jinshan114.png) no-repeat center center" title="999"></li>
    <li style="background: url(../images/jumeiyoupin114.png) no-repeat center center" title="1010"></li>
    <li style="background: url(../images/qingnian114.png) no-repeat center center" title="1111"></li>
    <li style="background: url(../images/aiqiyi114.png) no-repeat center center" title="333"></li>
    <li style="background:url(../images/91.jpg) no-repeat center center" title="222"></li>
    <li style="background: url(../images/fushi114.png) no-repeat center center" title="666"></li>
    <li style="background: url(../images/hangban114.png) no-repeat center center" title="777"></li>
    <li style="background:url(../images/91.jpg) no-repeat center center" title="222"></li>
    <li style="background: url(../images/jinshan114.png) no-repeat center center" title="999"></li>
    <li style="background: url(../images/jumeiyoupin114.png) no-repeat center center" title="1010"></li>
    <li style="background: url(../images/qingnian114.png) no-repeat center center" title="1111"></li>
    <li style="background: url(../images/qiyi114.png) no-repeat center center" title="2222222222"></li>
    <li style="background: url(../images/qiyi114.png) no-repeat center center" title="2222222222"></li>
    <li style="background: url(../images/qiyi114.png) no-repeat center center" title="2222222222"></li>
    <li style="background: url(../images/qiyi114.png) no-repeat center center" title="2222222222"></li>
    <li style="background: url(../images/qiyi114.png) no-repeat center center" title="2222222222"></li>
    </ul>
    </div>
    <script type="text/javascript">
    $(function(){
    var obj_box=$("#ad_box"); //获取ul元素的外部div
    var obj_ads=$("#ads"); //获取图片所在ul元素
    var li_lens=$("#ads li").length;
    var li_w=$("#ads li").width()+2; //获取li元素的宽度
    //alert(li_w);
    var d_x,m_x,u_x,iNow=0;
    var flag = false;

    //一次能够显示的图片个数
    var d_lis = parseInt(obj_box.width()/li_w , 10);

    obj_box.mousedown(function(event){
    flag = true;
    d_x = event.pageX; //获取鼠标点击下去时的横坐
    });
    obj_box.mousemove(function(event){

    if(flag == true){

    m_x = event.pageX;
    var _x = m_x - d_x;
    if(Math.abs(_x)>=50){

    if(_x>0){
    iNow--;
    if(iNow<0){
    iNow=0;
    }
    } else if(_x<0){

    iNow++;
    if(iNow>=Math.ceil(li_lens/d_lis)){
    iNow=Math.ceil(li_lens/d_lis)-1;
    }
    }
    obj_ads.animate({
    "left" : -iNow*d_lis*li_w
    },1000);
    flag = false;
    }

    }
    });

    obj_box.mouseup(function(){

    flag = false;
    });

    });
    </script>
    </body>
    </html>

  • 相关阅读:
    HarmonyOS Java UI之AdaptiveBoxLayout布局示例
    【鸿蒙开发板试用报告】OneNet平台+开发板实时监控温湿度(一)
    安装了瑞友天翼4.0后出现了远程桌面无法连接的问题
    CISVC.EXE的资源占用
    Delphi如何在窗体标题栏添加按钮
    Delphi中捕捉窗体的最小化、最大化、还原消息
    打印机任务无法删除
    Delphi创建一个虚幻的层窗口(Win2000/XP)
    工资年结时提示“上年数据已经结转”
    Delphi中如何控制其他程序窗体上的窗口控件
  • 原文地址:https://www.cnblogs.com/koukouyifan/p/3172159.html
Copyright © 2020-2023  润新知