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);
                })
            }
        }
  • 相关阅读:
    n的阶乘
    只出现一次的数字
    2的幂次方
    海康摄像头调用程序
    对象和Map转化gongju
    base64和图片的相互转换
    三员管理的定义
    关于注解的理解
    vue开发环境和生产环境里面解决跨域的几种方法
    thymeleaf 入门
  • 原文地址:https://www.cnblogs.com/hellobajie/p/6957631.html
Copyright © 2011-2022 走看看