實現按住鼠標拖動滾動:dragscroll

jopen 10年前發布 | 21K 次閱讀 前端技術 dragscroll

Dragscroll是一個很小的javascript庫(978 bytes minified),能夠通過實現按住鼠標拖動實現頁面滾動(drag-n-drop style, online demo).

用法

Download the distribution, unpack it and load thedragscroll.jsin a preferrable way. That is an UMD module, thus for instance it may simply be loaded as a plain JavaScript file using the<script>tag:

<script src="dragscroll.js"></script>

Add thedragscrollclass to a scrollable element:

<div class=dragscroll>
    Big text goes here...
</div>

That's it! Now you can scroll it by dragging. You can also add thedragscrollclass to the<body>element and drag the whole page.

Keep in mind that now it is not possible to select the content with mouse, so apply thecursor: default;CSS style to prevent confusing the users (or evencursor: grab;in case the content is not a text).

If you add (or remove) thedragscrollclass after the page was loaded, invokedragscroll.reset()to update the listeners.

項目主頁:http://www.baiduhome.net/lib/view/home/1427082176559

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!