2013-09-25 1 views
0

를 이동할 때 내가 여기에 간단한 테이블 열 크기 변경 내장 한 핸들 위로 마우스 커서를 유지 :이에 대한 플러그인을 사용할 수 없습니다마우스

http://jsfiddle.net/44k6c/

을하지만이 플러그인의 기능을 모방 할 필요가 :

http://quocity.com/colresizable/

나는 등 잘 리사이징 COLS을 관리했지만 내 커서가 핸들합니다 (일의 회색 상자)에서 멀리 이동할 수있다. 어떻게 든 커서를 제한해야 마우스가 움직일 때 핸들 위에 유지됩니다. 위의 플러그인 소스 코드를 살펴 봤지만이를 달성하는 방법에 대해 밝히지 않았습니다.

내 JS 코드 진행중인 작품이다 순간에 상당히 거친 :

$(document).ready(function() { 

       var th, 
        previousColIndex, 
        nextColIndex, 
        previousColWidth, 
        nextColWidth, 
        thWidth, 
        currentXPos; 

       $('.resize').mousedown(function(e) { 
        currentXPos = e.pageX; 
        th = $(this).parent(); 
        nextColIndex = th.index() + 1; 
        nextColWidth = $('table tr th').eq(nextColIndex).width(); 
        thWidth = th.width(); 
        $(document).bind('mousemove',function(e){ 
         if(e.pageX < currentXPos) { 
          thWidth = thWidth - 1; 
          nextColWidth = nextColWidth + 1; 
          $('table tr td').eq(th.index()).css({'width': thWidth + 'px'}); 
          th.css({'width':thWidth + 'px' }); 
          $('table tr td,table tr th').eq(nextColIndex).css({'width': nextColWidth + 'px'}); 
          currentXPos = e.pageX; 
         } else { 
          thWidth = thWidth + 1; 
          nextColWidth = nextColWidth - 1; 
          $('table tr td').eq(th.index()).css({'width': thWidth + 'px'}); 
          th.css({'width':thWidth + 'px' }); 
          $('table tr td,table tr th').eq(nextColIndex).css({'width': nextColWidth + 'px'}); 
          currentXPos = e.pageX; 
         } 


        }) 
       }).mouseup(function(){ 


$(document).unbind('mousemove'); 


}) 

    $(document).mouseup(function() { 
    $(document).unbind('mousemove'); 

}) 
}) 
+0

나는 당신을 생각하지 않으며 당신이 커서를 제한해야한다고 생각하지 않습니다. 커서는 OS에 내장되어 있습니다. 어쩌면 가능할 수도 있지만, 그런 기본적인 기능을 다시 작성하는 것이 좋다고 생각하지 않습니다. – Chad

+0

글쎄, 움직이는 게 훨씬 나아 졌다고 생각해. 문제는 마우스가 반대 방향으로 움직이는 것이다. 그것을 차단하는 방법을 모르겠지만 그것은 훨씬 덜 직관적 인 것입니다. – Virus721

답변

1

jsFiddle이 문제를 해결합니까?

thWidth = thWidth - 1; 
nextColWidth = nextColWidth + 1; 

이 아마해야합니다 :

thWidth = thWidth - currentXPos + e.pageX; 
nextColWidth = nextColWidth + currentXPos - e.pageX; 

편집 : 나쁜 링크

당신은 아마이 라인에 문제가 있었다. 이 하나를 사용하십시오 : http://jsfiddle.net/44k6c/4/

+0

예, 물론입니다. 많은 감사 –

관련 문제