# Automatic scrolling when text selecting

**URL:** <https://pdfjs.community/t/automatic-scrolling-when-text-selecting/2537>\
**Category:** Technical Support\
**Created:** [April 24, 2023, 8:35am UTC](https://pdfjs.community/t/automatic-scrolling-when-text-selecting/2537 "2023-04-24T08:35:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamas.ravasz](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@tamas.ravasz](https://pdfjs.community/u/tamas.ravasz)\
**Post date:** [April 24, 2023, 8:35am UTC](https://pdfjs.community/t/automatic-scrolling-when-text-selecting/2537/1 "2023-04-24T08:35:27Z")

</div>

**Which product are you using?**  
PDF.js Express Viewer  
**PDF.js Express Version**  
8.7.1  
**Detailed description of issue**  
Is it possibly to have the page scrolling when the text selection is active, meaning when the user reaches the bottom of the page with the cursor scrolling should happen automatically.

**Expected behaviour**  
When the user reaches the bottom of the page with the cursor a scrolling action should be done until the user releases the left mouse button and the text selection is completed. The aim is to select text on multiple consecutive pages.

**Does your issue happen with every document, or just one?**  
All documents.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [April 24, 2023, 5:45pm UTC](https://pdfjs.community/t/automatic-scrolling-when-text-selecting/2537/3 "2023-04-24T17:45:18Z")

</div>

Hi there,

Thank you for contacting pdf.js express forums,

We do not have an automatic scrolling effect which holding click, but you could implement something like this using the documentViewer event and methods available:  
[https://pdfjs.express/api/Core.DocumentViewer.html](https://pdfjs.express/api/Core.DocumentViewer.html)

Here is a prototype:

```javascript
let active = true;
  documentViewer.addEventListener('mouseMove', (e) => {
    documentViewer.addEventListener('mouseLeftUp', (e) =>{
      active = false;
      return;
    })

    const scrollElement = documentViewer.getScrollViewElement();
    const scrollLeft = scrollElement.scrollLeft || 0;
    const scrollTop = scrollElement.scrollTop || 0;

    const coordinate = {
      x: e.pageX + scrollLeft,
      y: e.pageY + scrollTop
    }
    console.log(coordinate);

    if (active && e.pageY > 500) {
      const pageNumber = documentViewer.getCurrentPage();
      documentViewer.setCurrentPage(pageNumber + 1, true)
    }
  })

```

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![tamas.ravasz](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@tamas.ravasz](https://pdfjs.community/u/tamas.ravasz)\
**Post date:** [April 26, 2023, 5:40am UTC](https://pdfjs.community/t/automatic-scrolling-when-text-selecting/2537/4 "2023-04-26T05:40:28Z")

</div>

Hello,

Thank you for the answer I will try this prototype

Best regards,

Tamas
