zoukankan      html  css  js  c++  java
  • 导航条滑动效果

    一、无回弹效果

       function slide(id) {
            var UlWidth = 0;
            var touchStart, touchEnd, moveLength, startML, maxML; 
            $shop2 = $('#' + id);
            $shop2.find('li').each(function(){
                UlWidth += $(this).outerWidth();
            })
            $shop2.width(UlWidth);
            maxML = UlWidth - $(window).width();
            if(maxML > 0){
                $shop2.bind('touchstart', function(e){
                    touchStart = e.originalEvent.targetTouches[0].pageX;   
                    startML = $shop2.css('margin-left');
                }).bind('touchmove', function(e){
                    touchEnd = e.originalEvent.targetTouches[0].pageX; 
                    moveLength = touchEnd - touchStart + parseInt(startML) ;
                    if(moveLength > 0){
                        moveLength = 0;
                    }else if(moveLength < -maxML){
                        moveLength = -maxML;
                    }
                    $shop2.css('margin-left', moveLength)
                })
            }
        }

    二、有回弹效果

      function slide(id) {
            var UlWidth = 0;
            var touchStart, touchEnd, moveLength, startML, maxML; 
            $shop2 = $('#' + id);
            $shop2.find('li').each(function(){
                UlWidth += $(this).outerWidth();
            })
            $shop2.width(UlWidth);
            maxML = UlWidth - $(window).width();
            if(maxML > 0){
                $shop2.bind('touchstart', function(e){
                    touchStart = e.originalEvent.targetTouches[0].pageX;   
                    startML = $shop2.css('margin-left');
                }).bind('touchmove', function(e){
                    touchEnd = e.originalEvent.targetTouches[0].pageX; 
                    moveLength = touchEnd - touchStart + parseInt(startML);
                    $shop2.css('margin-left', moveLength)
                }).bind('touchend', function(){
                    if(moveLength > 0){
                        moveLength = 0;
                    }else if(moveLength < -maxML){
                        moveLength = -maxML;
                    }
                    $shop2.animate({'marginLeft': moveLength}, 200);
                })
            }
        }
  • 相关阅读:
    Ubuntu 16.04 安装 Apache, MySQL, PHP7
    Ubuntu下apache2启动、停止、重启、配置
    织梦-数据库-表和字段说明手册
    DEDECMS去除后门隐患和漏洞以及冗余代码的方法
    Express使用html模板
    windows系统 安装MongoDB
    linux搭建node.js环境
    配置vuejs加载模拟数据
    安卓高级5 zXing
    安卓高级5 传感器和震动 模仿微信摇一摇Ui效果
  • 原文地址:https://www.cnblogs.com/hellobajie/p/6957631.html
Copyright © 2011-2022 走看看