2011-09-09 5 views
1

내 응용 프로그램에서 스크롤바가 오는 곳은 사용자 정의 스크롤바로 변경해야합니다. CSS에서 스크롤바 스타일을 지정하는 방법은 없습니다. 스크롤바 사용자 정의와 관련된 제안 사항을 알려주십시오.사용자 정의 스크롤바

jquery 플러그인을 사용자 지정 스크롤바에 대해 보았습니다. 그러나 사용자 지정 스크롤 막대에 대한 각 위치를 변경해야합니다. 대신 한 곳에서 변경하면 스크롤바가 올 모든 장소에 영향을 줄 수있는 방법이 있습니까? 내 응용 프로그램.

답변

1

WebKitolder IE에 스크롤바의 스타일을 지정할 수 있습니다.

모든 스크롤 막대에 적용하려면 body, textarea, .any-other-element-with-overflow-scroll과 같은 선택기를 사용할 수 있어야합니다.

사용자 지정 스크롤 막대를 사용할 때는 usability issues을 고려하십시오.

+0

어떻게 될 브라우저 support.If을 나는 웹킷 스타일을 사용 – Bhaskar

+0

@Bhaskar WebKit 렌더링 엔진을 사용하는 장치. 여기에는 Chrome과 Safari가 포함됩니다. – alex

+0

+1 유용성 문제를 언급합니다. – nnnnnn

5

나는 custom scrollbar library named SimpleScrollbar을 개발했습니다.

다른 라이브러리/프레임 워크에 의존하지 않으며 gzip 및 축소 후 1KB 미만입니다.

네이티브 스크롤을 사용하므로 해킹이 없으므로 성능이 좋습니다.


는 당신은 당신의 페이지에있는 라이브러리를 포함하고 스크롤 가능하게하려는 사업부의 ss-container 속성을 사용해야합니다. 라이브 예 :

<link href="http://buzinas.github.io/simple-scrollbar/simple-scrollbar.css" rel="stylesheet"/> 
 
<div style="height: 180px; width: 200px; display: inline-block;" ss-container> 
 
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 
 
</div> 
 
<section style="height: 180px; width: 300px; display: inline-block;" ss-container> 
 
    <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p> 
 
     <p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</p> 
 
</section> 
 
<!--[if IE 9]><script src="https://cdn.jsdelivr.net/classlist/2014.01.31/classList.min.js"></script><![endif]--> 
 
<script src="http://buzinas.github.io/simple-scrollbar/simple-scrollbar.min.js"></script>

그것은 모든 최신 브라우저 (파이어 폭스, 크롬, 오페라, 사파리, 가장자리)에 작동하고, IE10 및 IE11에

. IE9에서 classList polyfill을 포함하여 사용할 수도 있습니다.

모든 Android, iOS 및 Windows Phone 브라우저가 지원됩니다. 자동 이미 스크롤이 모든 요소를 ​​찾으려면


, 당신은 그런 식으로 뭔가를 할 수 있습니다

// After all the content in your page has loaded 
document.addEventListener('DOMContentLoaded', function() { 
    // Get all elements in your page 
    var elements = document.querySelectorAll('*'), el; 
    for (var i = 0; i < elements.length, el = elements[i]; i++) { 
    // If the scrollheight is higher than the clientheight, it's because it has a scrollbar 
    if (el.scrollHeight > el.clientHeight) { 
     SimpleScrollbar.initEl(el); // turn the element into a SimpleScrollbar one 
    } 
    } 
}); 
+0

SimpleScrollbar는 스크롤 막대를 전혀 표시하지 않고 (마우스 휠을 사용할 때 기능을 유지함) 대신 [Sly] (http://darsa.in/sly/)와 같이 두 개의 버튼 (하나의 요소 및/또는 페이지를 위/아래로 이동)을 표시 할 수 있습니까? 나는 jQuery에 의존하지 않기를 정말로 좋아하기 때문에 나는 당신을 사용하고 싶다. – domsson

+0

CSS를 덮어 쓰면됩니다 (예 :'.ss-container : hover .ss-scroll { opacity : 0; }'. – Buzinas

관련 문제