드래그 컨트롤

6640 단어
매일 조금씩 공부하다먼저 사용된 모듈을 불러올 때 seaJS
define(function(require, exports, module) {})------------------------- 。
module.exports = {   
            AssistiveTouch: AssistiveTouch
                    };---------------------------------------------- , 。

2. 클릭 | | | 터치 위치 (호환)
function mousePosition(ev){    
if(ev.targetTouches&&ev.targetTouches[0]){
        return {x:ev.targetTouches[0].pageX, y:ev.targetTouches[0].pageY};    
}    
if(ev.touches&&ev.touches[0]){
        return {x:ev.touches[0].pageX, y:ev.touches[0].pageY};    
}    
if(ev.changedTouches&&ev.changedTouches[0]){
        return {x:ev.changedTouches[0].pageX, y:ev.changedTouches[0].pageY};    
}    
if(ev.pageX || ev.pageY){
        return {x:ev.pageX, y:ev.pageY};    
}    
return {        
          x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,        
          y:ev.clientY + document.body.scrollTop - document.body.clientTop      
      };
}

3. 컨트롤 대상 자체
function AssistiveTouch(sets,clickFunc){
      var atClass=(sets.atClass)?sets.atClass:“”,
           imgUrl=(sets.imgUrl)?sets.imgUrl:",             // 
           closeBtn=(sets.closeBtn)?sets.closeBtn:false;  //  
           clipH=(sets.clipH)?sets.clipH:0;                // 
           clipW = (sets.clipW)?sets.clipW:0,              // 
           autoSide=(sets.autoSide)?sets.autoSide:false;   // 
    $(atClass).css("position","fixed");
    $(atClass).css("z-index","100");
    $(atClass).append('
'); ---- if(imgUrl){ $(".assistive-touch-content").css("background-image","url('"+imgUrl+"')");} if(closeBtn){ $(atClass).append('
×
'); } $(".assistive-touch-close-btn").on(" click mouseup touchend",function(e){ // window.event? window.event.cancelBubble = true : e.stopPropagation(); $(atClass).hide(); }); ---------------------------------------------------- $(atClass).on("mousedown touchstart",function(e){ var e=e||window.event; e.preventDefault(); var mousePos=mousePosition(e); $(this).attr("moving","true"); $(this).attr("offset-left",mousePos.x-$(this)[0].offsetLeft); $(this).attr("offset-top",mousePos.y-$(this)[0].offsetTop); $(this).attr("origin-left",mousePos.x); $(this).attr("origin-top",mousePos.y); })------------------------------------------------- $(atClass).on("mouseup touchend",function(e){ if($(this).attr("moving")!="true")return; var e=e||window.event; e.preventDefault(); var mousePos=mousePosition(e); $(this).[0].style.left = (mousePos.x-$(this).attr("offset-left"))+"px"; $(this)[0].style.top = (mousePos.y-$(this).attr("offset-top"))+"px"; })------------------------------------------------- $(atClass).on("mouseup touchend",function(e){ var e=e||window.event; e.preventDefault(); var windowHeight = document.documentElement.clientHeight||document.body.clientHeight; var windowWidth = document.documentElement.offsetWidth||document.body.offsetWidth; windowHeight += clipH; windowWidth += clipW; $(this).attr("moving","false"); var mousePos = mousePosition(e); $(this)[0].style.top = (mousePos.y-$(this).attr("offset-top"))+"px"; if(Math.abs(mousePos.x-$(this).attr("origin-left"))<=3||Math.abs(mousePos.y-$(this).attr("origin-top"))<=3){ $(this)[0].style.left = ($(this).attr("origin-left")-$(this).attr("offset-left"))+"px"; $(this)[0].style.top = ($(this).attr("origin-top")-$(this).attr("offset-top"))+"px"; $(this).click(function(e){ clickFunc($(".assistive-touch-content")[0],$(this)[0]); }); $(this).click(); return; } $(".assistive-touch-close-btn").removeClass("right").removeClass('top'); function sideOverflowFunc(t) { if(t[0].offsetLeft<0){ t[0].style.left = 0; } if((t[0].offsetTop+t[0].offsetHeight)>windowHeight){ t[0].style.top = (windowHeight - t[0].offsetHeight)+"px"; } if((t[0].offsetLeft+t[0].offsetWidth)>windowWidth){ t[0].style.left = (windowWidth - t[0].offsetWidth)+"px"; $(".assistive-touch-close-btn").addClass("right"); } }-------------------------------------------------------------------- function autoSideFunc(t){ if (!autoSide)return; if(t[0].offsetTopwindowHeight/10*9){ t.animate({top:(windowHeight-t[0].offsetHeight)+"px"},200); return; } if(t[0].offsetLeft+(t[0].offsetWidth/2)<=windowWidth/2){ t.animate({left:"0px"},200); }else{ t.animate({left:(windowWidth-t[0].offsetWidth)+"px"},200); $(".assistive-touch-close-btn").addClass("right"); } }-------------------------------------------------------------- sideOverflowFunc($(this)); autoSideFunc($(this)); })------------------------------------------------------------------ return $(atClass);-------------------------------------------------------- }

4.调用:

assTouch.AssistiveTouch({    
    atClass:".js_drap_img",    
    imgUrl:config.baseloc+"images/index/fenqi2_icon.png",
    closeBtn:false,    
    autoSide:true,    
    clipH:-50
},function(content,self){    
    com.jumpUrl("lend/frontstage.html?productId=1&footer=1&productType=2",config.USERCERTIFICATION);
});

좋은 웹페이지 즐겨찾기