ScrollPanelScrollPanel is a cross browser, lightweight and skinnable alternative to native browser scrollbar.

ScrollPanel - 图1

Documentation

Import

  1. import {ScrollPanelModule} from 'primeng/scrollpanel';
  2.  

Getting Started

ScrollPanel is defined with p-scrolPanel element having dimensions for the scrollable viewport.

  1. <p-scrollPanel [style]="{width: '100%', height: '200px'}">
  2. Content
  3. </p-scrollPanel>
  4.  

Customization

Look and feel can easily be customized, here is an example with a background and blue handle.

  1. <p-scrollPanel [style]="{width: '100%', height: '200px'}" styleClass="custom">
  2. Content
  3. </p-scrollPanel>
  4.  
  1. .custom .ui-scrollpanel-wrapper {
  2. border-right: 9px solid #f4f4f4;
  3. }
  4. .custom .ui-scrollpanel-bar {
  5. background-color: #1976d2;
  6. opacity: 1;
  7. transition: background-color .3s;
  8. }
  9. .custom .ui-scrollpanel-bar:hover {
  10. background-color: #135ba1;
  11. }
  12.  

Properties

NameTypeDefaultDescription
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-scrollpanelContainer element.
ui-scrollpanel-wrapperWrapper of content section.
ui-scrollpanel-contentContent section.
ui-scrollpanel-barScrollbar handle.
ui-scrollpanel-bar-xScrollbar handle of a horizontal bar.
ui-scrollpanel-bar-yScrollbar handle of a vertical bar

Methods

NameParametersDescription
refresh-Refreshes the position and size of the scrollbar.
scrollTopvalue: numberScrolls the top location to the given value.

Dependencies

None.

Source

View on GitHub

  1. <div class="ui-g">
  2. <div class="ui-g-12 ui-md-4">
  3. <p-scrollPanel [style]="{width: '100%', height: '200px'}">
  4. <div style="padding:1em;line-height:1.5">
  5. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved
  6. son Michael has just come home from the war, but does not intend to become part of his father's business.
  7. Through Michael's life the nature of the family business becomes clear. The business of the family is just
  8. like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence
  9. whenever anything stands against the good of the family. The story begins as Don Vito Corleone, the head
  10. of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from
  11. the war, but does not intend to become part of his father's business. Through Michael's life the nature of
  12. the family business becomes clear. The business of the family is just like the head of the family, kind and
  13. benevolent to those who give respect, but given to ruthless violence whenever anything stands against the
  14. good of the family.
  15. </div>
  16. </p-scrollPanel>
  17. </div>
  18. <div class="ui-g-12 ui-md-4">
  19. <p-scrollPanel [style]="{width: '100%', height: '200px'}" styleClass="custombar1">
  20. <div style="padding:1em;line-height:1.5">
  21. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved
  22. son Michael has just come home from the war, but does not intend to become part of his father's business.
  23. Through Michael's life the nature of the family business becomes clear. The business of the family is just
  24. like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence
  25. whenever anything stands against the good of the family. The story begins as Don Vito Corleone, the head
  26. of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from
  27. the war, but does not intend to become part of his father's business. Through Michael's life the nature of
  28. the family business becomes clear. The business of the family is just like the head of the family, kind and
  29. benevolent to those who give respect, but given to ruthless violence whenever anything stands against the
  30. good of the family.
  31. </div>
  32. </p-scrollPanel>
  33. </div>
  34. <div class="ui-g-12 ui-md-4">
  35. <p-scrollPanel [style]="{width: '100%', height: '200px'}" styleClass="custombar2">
  36. <div style="padding:1em;line-height:1.5;width:600px;">
  37. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved
  38. son Michael has just come home from the war, but does not intend to become part of his father's business.
  39. Through Michael's life the nature of the family business becomes clear. The business of the family is just
  40. like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence
  41. whenever anything stands against the good of the family. The story begins as Don Vito Corleone, the head
  42. of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from
  43. the war, but does not intend to become part of his father's business. Through Michael's life the nature of
  44. the family business becomes clear. The business of the family is just like the head of the family, kind and
  45. benevolent to those who give respect, but given to ruthless violence whenever anything stands against the
  46. good of the family.
  47. </div>
  48. </p-scrollPanel>
  49. </div>
  50. </div>
  51.  
  1. @Component({
  2. templateUrl: './scrollpaneldemo.html',
  3. styles: [`
  4. .custombar1 .ui-scrollpanel-wrapper {
  5. border-right: 9px solid #f4f4f4;
  6. }
  7. .custombar1 .ui-scrollpanel-bar {
  8. background-color: #1976d2;
  9. opacity: 1;
  10. transition: background-color .3s;
  11. }
  12. .custombar1 .ui-scrollpanel-bar:hover {
  13. background-color: #135ba1;
  14. }
  15. .custombar2 .ui-scrollpanel-wrapper {
  16. border-right: 9px solid #757575;
  17. border-bottom: 9px solid #757575;
  18. }
  19. .custombar2 .ui-scrollpanel-bar {
  20. background-color: #68C77D;
  21. border-radius: 0;
  22. opacity: 1;
  23. transition: background-color .3s;
  24. }
  25. .custombar2:hover .ui-scrollpanel-bar {
  26. background-color: #46A55A;
  27. }
  28. `],
  29. encapsulation: ViewEncapsulation.None
  30. })
  31. export class ScrollPanelDemo {
  32. }
  33.