zoukankan      html  css  js  c++  java
  • touchSwipe 上下左右滑动,二指缩放 效果不好。

    $(function(){
    var _showImgW;
    var _showImgH;
    var _showImgMT;
    var _showImgML;
    $("#imgDiv").swipe({
    swipeStatus:function(event, phase, direction, distance , duration , fingerCount) {
    //$(this).find('#swipe_text').text("swiped " + distance + ' px');
    if(phase === $.fn.swipe.phases.PHASE_END || phase === $.fn.swipe.phases.PHASE_CANCEL) {
    //$(this).find('#swipe_text').text("No swipe was made");
    }
    if (phase == "start")
    {
    _showImgMT = $(this).find("._showImg").css("margin-top").replace("px", "");
    _showImgML = $(this).find("._showImg").css("margin-left").replace("px", "");
    }
    if (direction == "up" && (phase == "cancel" || phase == "end")) {
    //向上滑动 到顶
    var mt = _showImgMT + duration;
    //$(this).find("._showImg").css("margin-top",mt+"px");
    }
    else if (direction == "down" && (phase == "cancel" || phase == "end")) {
    //向下滑动 到顶
    var ml = _showImgML - duration;
    //$(this).find("._showImg").css("margin-left",ml+"px");
    }
    else if (direction == "left" && (phase == "cancel" || phase == "end")) {
    //向左滑动 到顶
    var ml = _showImgML - duration;
    //$(this).find("._showImg").css("margin-left",ml+"px");
    }
    else if (direction == "right" && (phase == "cancel" || phase == "end")) {
    //向右滑动 到顶
    var ml = _showImgML - duration;
    //$(this).find("._showImg").css("margin-left",ml+"px");
    }

    if (direction == "up" && phase != "cancel" && phase != "end") {
    //向上滑动过程中
    var h = $(this).find("._showImg").height();
    var mt = _showImgMT - duration;
    if(get_height_for_window()-h>mt)
    mt = get_height_for_window()-h;
    //$(this).find("._showImg").css("margin-top",mt+"px");
    $(this).find("._showImg").animate({ marginTop: mt + 'px' }, 100);
    }
    else if (direction == "down" && phase != "cancel" && phase != "end") {
    //向下滑动过程中
    _showImgMT = $(this).find("._showImg").css("margin-top").replace("px", "");
    var mt = _showImgMT + duration;
    if(mt<=0)
    mt = 0;
    //$(this).find("._showImg").css("margin-top",mt+"px");
    $(this).find("._showImg").animate({ marginTop: mt + 'px' }, 100);
    }
    else if (direction == "left" && phase != "cancel" && phase != "end") {
    //向左滑动过程中
    var w = $(this).find("._showImg").width();
    var ml = _showImgML - duration;
    if(get_width_for_window()-w>ml)
    ml = get_width_for_window()-w;
    //$(this).find("._showImg").css("margin-left",ml+"px");
    $(this).find("._showImg").animate({ marginLeft: ml + 'px' }, 100);
    }
    else if (direction == "right" && phase != "cancel" && phase != "end") {
    //向右滑动过程中
    _showImgML = $(this).find("._showImg").css("margin-left").replace("px", "");
    var ml = _showImgML + duration;
    if(ml<=0)
    ml = 0;
    //$(this).find("._showImg").css("margin-left",ml+"px");
    $(this).find("._showImg").animate({ marginLeft: ml + 'px' }, 100);
    }
    },
    pinchStatus:function(event, phase, direction, distance , duration , fingerCount, pinchZoom) {
    if(phase == "start") {
    _showImgW =$(this).find("._showImg").width();
    _showImgH = $(this).find("._showImg").height();
    }
    if(direction=="in")
    { //pinchZoom 缩放比例
    var w = _showImgW*pinchZoom;
    var h = _showImgH*pinchZoom;
    $(this).find("._showImg").css("width", w + 'px' );
    $(this).find("._showImg").css("height", h + 'px' );
    }
    else if(direction=="out")
    {
    var w = _showImgW*pinchZoom;
    var h = _showImgH*pinchZoom;
    $(this).find("._showImg").css("width", w + 'px' );
    $(this).find("._showImg").css("height", h + 'px' );
    }
    },
    swipe:function(event, direction, distance, duration, fingerCount) {
    //$(this).find('#swipe_text').text("You swiped " + direction + " with " + fingerCount + " fingers");
    },
    pinchIn:function(event, direction, distance, duration, fingerCount, pinchZoom) {
    $(this).find('#pinch_text').text("You pinched " +direction + " by " + distance +"px, zoom scale is "+pinchZoom);
    //ecg.alert(direction + " by " + distance +"px");
    //$(this).find("._showImg").animate({ -duration + 'px' }, 0);
    },
    pinchOut:function(event, direction, distance, duration, fingerCount, pinchZoom) {
    $(this).find('#pinch_text').text("You pinched " +direction + " by " + distance +"px, zoom scale is "+pinchZoom);
    //ecg.alert(direction + " by " + distance +"px");
    },
    fingers:'all'
    });
    });

  • 相关阅读:
    git rebase学习
    git rebase 通俗易懂!
    fatal: Refusing to fetch into current branch refs/heads/ReqMerge_26 of non-bare repository
    跨越千年的RSA算法
    CodeForces 734E-Anton and Tree(并查集缩点+树的直径)
    程序员的笑话
    智慧煤矿:新基建加速智能化布局,AI助力煤炭产业转型升级
    EasyScreenLive推流组件推RTSP流到EasyDarwin操作过程分享
    EasyCVRpython调接口报错cannot unmarshal array into Go value of type main
    使用ninja -C out/Release指令编译安卓Webrtc的SDK报错找不到android ndk处理方式
  • 原文地址:https://www.cnblogs.com/90nice/p/4737447.html
Copyright © 2011-2022 走看看