question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable scroll on next page button click

See original GitHub issue
Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [x] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

I saw there was already a bug report created for this last year, but it appears that is not corrected in the latest version (6.3.0).

Every time I change a page, it automatically scrolls to the top of the document which is disrupting to the user because they have to scroll back up again to see the buttons.

Here is my code:

<div class="pdf-container">
    <div *ngIf="isLoaded" class="pdf-page-btns" style="text-align: center;">
        <button (click)="prevPage($event)" [disabled]="page === 1">Prev</button>
                    <span>{{ page }} / {{ totalPages }}</span>
        <button (click)="nextPage($event)" [disabled]="page === totalPages">Next</button>
    </div>

    <pdf-viewer [src]="pdfSrc" [show-all]="false" [page]="page" [render-text]="true" 
     [original-size]="false" [stick-to-page]="false" 
    (after-load-complete)="afterLoadComplete($event)" style="display: block;">
     </pdf-viewer>
</div>

Here is my styling:

.pdf {
    &-container {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-content: center;
        align-items: center;
        padding: 2em;
        @extend .section; // this just adds background color and box-shadow
    }
    &-page-btns {
        text-align: center;
        margin-bottom: 2em;
        & button {
            margin: 10px;
        }
    }
}

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
CesarUCIGITcommented, Oct 4, 2020

I have found a workaround that doesn’t involve directly changing the pdfjs module. So what you need to do is to capture on your component the PdfViewerComponent. Then you can access the pdfviewer and inside there is an object call scroll.down and you can set it to false. And that’s it you will no longer have scrolling when changing pages.

Angular Component

@ViewChild(PdfViewerComponent, { static: false })
   private pdfComponent: PdfViewerComponent;

initLoadCompleted(pdf: PDFDocumentProxy): void {
       this.pdfComponent.pdfViewer.scroll.down = false;
   }

HTML

<pdf-viewer
                  [src]="pdfData" (after-load-complete)="initLoadCompleted($event)"
                  [render-text]="true"
                  [page]="currentPage"
                  [show-all]="false">
      </pdf-viewer>
0reactions
stale[bot]commented, Dec 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent page scroll after click? - Stack Overflow
Another solution is add a "/" after the "#": ... The reason that it is going to the top of the page is...
Read more >
How to disable scrolling temporarily using JavaScript
This will enable the scrolling of the page again. Pseudo Code: ... < p >Click on the buttons below to enable or disable...
Read more >
Disable Scrolling on Click (compatible with all devices)
Use the code in this project to easily prevent the users from scrolling when clicking any element.
Read more >
Prevent Scroll On Scrollable Elements [JS & CSS] - Alvaro Trigo
There's another way to disable scrolling that is commonly used when opening modals or scrollable floating elements. And it is simply by adding ......
Read more >
Turn off Scroll Lock - Microsoft Support
If your computer does not have a Scroll Lock key, do one of the following: ... Click the On Screen Keyboard button to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found