Guide applies to: modern

Using Carousels

Carousels are a great way to allow users to swipe through multiple full screen pages.

A Carousel shows only one of its pages at a time, but allows you to browse through other pages using a swipe gesture. You can think of a Carousel as a single active item, with the rest of the items stretching away left and right. Indicator dots visualize how many available screens are available to swipe through, as shown in the following image:

Carousel - 图1

Carousels can be oriented either horizontally or vertically and are easy to configure - they just work like any other Container component. The following code sample shows how to set up a simple horizontal Carousel:

Expand Code

JS Run

  1. Ext.create('Ext.Carousel', {
  2. fullscreen: true,
  3. defaults: {
  4. styleHtmlContent: true
  5. },
  6. items: [
  7. {
  8. html : 'Item 1',
  9. style: 'background-color: #5E99CC'
  10. },
  11. {
  12. html : 'Item 2',
  13. style: 'background-color: #759E60'
  14. },
  15. {
  16. html : 'Item 3'
  17. }
  18. ]
  19. });

Swiping your finger left and right over the carousel swaps between the three items defined above. It also updates the indicator icon to let you know which page you are currently on. We can also make Carousels orient themselves vertically, as shown in the following code sample:

Expand Code

JS Run

  1. Ext.create('Ext.Carousel', {
  2. fullscreen: true,
  3. direction: 'vertical',
  4. defaults: {
  5. styleHtmlContent: true
  6. },
  7. items: [
  8. {
  9. html : 'Item 1',
  10. style: 'background-color: #759E60'
  11. },
  12. {
  13. html : 'Item 2',
  14. style: 'background-color: #5E99CC'
  15. }
  16. ]
  17. });

You can place any component into a Carousel, for example the following code places a list and a form into a horizontal carousel:

Expand Code

JS Run

  1. Ext.create('Ext.Carousel', {
  2. fullscreen: true,
  3. items: [
  4. {
  5. xtype: 'list',
  6. items: {
  7. xtype: 'toolbar',
  8. docked: 'top',
  9. title: 'Roster'
  10. },
  11. store: {
  12. fields: ['name'],
  13. data: [
  14. {name: 'Jon'},
  15. {name: 'Sansa'},
  16. {name: 'Arya'},
  17. {name: 'Robb'},
  18. {name: 'Bran'},
  19. {name: 'Rickon'}
  20. ]
  21. },
  22. itemTpl: '{name}'
  23. },
  24. {
  25. xtype: 'fieldset',
  26. items: [
  27. {
  28. xtype: 'toolbar',
  29. docked: 'top',
  30. title: 'Login'
  31. },
  32. {
  33. xtype: 'textfield',
  34. label: 'Name'
  35. },
  36. {
  37. xtype: 'passwordfield',
  38. label: 'Password'
  39. }
  40. ]
  41. }
  42. ]
  43. });