2012-07-04 2 views
0

이것은 Mac 문제 일 수 있습니다. 그러나 페이지 크기의 두 배이며 동적으로보기로 이동되는 요소가있는 페이지가 있습니다. 내 css에 난 overflow-x :이 요소가 못생긴 하단의 scollbar를 만들지 않도록 설정, 문제는 내 노트북에 (그리고 아마도 ipads 및 기타 장치에) 난 그냥 두 손가락으로 스크롤 할 수 있습니다 스크롤 이 콘텐츠를 봅니다. 이것은 전체 레이아웃을 깨고 정말 나쁜 것처럼 보입니다. javascript 나 css로이 수평 스크롤 동작을 완전히 비활성화하는 방법을 찾고 있습니다. 사용자가 스크롤하려고 할 때마다 원래의 (0,0) 위치의에손가락 스 와이프로 가로 스크롤 사용 안 함

window.onscroll = function() { 
    window.scrollTo(0,0); 
    } 

이 다시 스크롤 막대를 반환합니다

당신에게

답변

2

자바 스크립트 감사드립니다. 데스크톱 에서처럼 노트북 패드에서 작동하는지 알려주세요.

+0

가로 스크롤링 만 사용 중지하려면이 기능을 사용할 수 있습니까? 수직 스크롤을 허용하고 싶습니다. – codelove

+0

이것은 작동하지 않습니다. 화면을 제자리에 고정시키고 모든 스크롤을 방지합니다. 또한, 당신이 그것을 변경하더라도 : window.scrollTo (0, jQuery (window) .scrollTop()); 수직으로 스크롤하는 것이 심하게 방해됩니다. 아래 내 솔루션을 사용해보십시오. – deweydb

0

먼저 스크롤이 중단 된 시간을 확인하는 기능을 사용했습니다. 그런 다음 다른 기능을 사용하여 센터로 다시 이동했습니다.

(function(){ 

var special = jQuery.event.special, 
    uid1 = 'D' + (+new Date()), 
    uid2 = 'D' + (+new Date() + 1); 

special.scrollstart = { 
    setup: function() { 

     var timer, 
      handler = function(evt) { 

       var _self = this, 
        _args = arguments; 

       if (timer) { 
        clearTimeout(timer); 
       } else { 
        evt.type = 'scrollstart'; 
        jQuery.event.handle.apply(_self, _args); 
       } 

       timer = setTimeout(function(){ 
        timer = null; 
       }, special.scrollstop.latency); 

      }; 

     jQuery(this).bind('scroll', handler).data(uid1, handler); 

    }, 
    teardown: function(){ 
     jQuery(this).unbind('scroll', jQuery(this).data(uid1)); 
    } 
}; 

special.scrollstop = { 
    latency: 300, 
    setup: function() { 

     var timer, 
       handler = function(evt) { 

       var _self = this, 
        _args = arguments; 

       if (timer) { 
        clearTimeout(timer); 
       } 

       timer = setTimeout(function(){ 

        timer = null; 
        evt.type = 'scrollstop'; 
        jQuery.event.handle.apply(_self, _args); 

       }, special.scrollstop.latency); 

      }; 

     jQuery(this).bind('scroll', handler).data(uid2, handler); 

    }, 
    teardown: function() { 
     jQuery(this).unbind('scroll', jQuery(this).data(uid2)); 
    } 
}; 

})(); 

jQuery(window).bind('scrollstop', function(e){ 
    // block horizontal scrolling 
    window.scrollTo(0,jQuery(window).scrollTop()); 
}); 
관련 문제