Guide applies to: modern

Introduction

In this lab, you’ll make tuneview look better. That requires making the items float, and assigning a fixed height and width — that’s done through Sass and CSS.

1.Create a Sass file

Create a new file app/desktop/src/view/TunesView.scss with the following content.

  1. .tunes-view {
  2. background-color: #eeeeee;
  3. -webkit-transition: -webkit-filter 250ms;
  4. transition: -webkit-filter 250ms;
  5. -o-transition: filter 250ms;
  6. -moz-transition: filter 250ms;
  7. transition: filter 250ms;
  8. transition: filter 250ms, -webkit-filter 250ms;
  9. }
  10. .blur .tunes-view {
  11. -webkit-filter: blur(5px) grayscale(80%);
  12. filter: blur(5px) grayscale(80%);
  13. }
  14. .video:hover {
  15. -webkit-transform: scale(1.10);
  16. -moz-transform: scale(1.10);
  17. -o-transform: scale(1.10);
  18. transform: scale(1.10);
  19. box-shadow: 2px 2px 10px rgba(0,0,0,.2);
  20. .thumbnail {
  21. -webkit-filter: none;
  22. filter: none;
  23. }
  24. }
  25. .video {
  26. -webkit-transition: transform 500ms ease;
  27. -moz-transition: transform 200ms ease;
  28. -o-transition: transform 200ms ease;
  29. -webkit-transition: -webkit-transform 200ms ease;
  30. transition: -webkit-transform 200ms ease;
  31. -o-transition: -o-transform 200ms ease;
  32. -moz-transition: transform 200ms ease, -moz-transform 200ms ease;
  33. transition: transform 200ms ease;
  34. transition: transform 200ms ease, -webkit-transform 200ms ease, -moz-transform 200ms ease, -o-transform 200ms ease;
  35. width: 16vw;
  36. height: 16vw;
  37. text-align: center;
  38. background: #fff;
  39. color: #777;
  40. margin: 1.2vw;
  41. cursor: pointer;
  42. .thumbnail {
  43. width: 100%;
  44. height: 100%;
  45. background-size: cover;
  46. -webkit-transition: -webkit-filter 300ms;
  47. transition: -webkit-filter 300ms;
  48. -o-transition: filter 300ms;
  49. -moz-transition: filter 300ms;
  50. transition: filter 300ms;
  51. transition: filter 300ms, -webkit-filter 300ms;
  52. -webkit-filter: grayscale(80%);
  53. filter: grayscale(80%);
  54. }
  55. figure {
  56. display: -webkit-box;
  57. display: -webkit-flex;
  58. display: -moz-box;
  59. display: flex;
  60. -webkit-box-orient: vertical;
  61. -webkit-box-direction: normal;
  62. -webkit-flex-direction: column;
  63. -moz-box-orient: vertical;
  64. -moz-box-direction: normal;
  65. flex-direction: column;
  66. -webkit-box-align: center;
  67. -webkit-align-items: center;
  68. -moz-box-align: center;
  69. align-items: center;
  70. height: 100%;
  71. margin: 0;
  72. }
  73. figcaption {
  74. position: absolute;
  75. left: 0;
  76. bottom: 0;
  77. width: 100%;
  78. padding: .25vw 1vw;
  79. font-size: 1.1vw;
  80. overflow: hidden;
  81. background-color: rgba(0,0,0, .5);
  82. color: white;
  83. .title, .artist {
  84. overflow: hidden;
  85. text-overflow: ellipsis;
  86. white-space: nowrap;
  87. }
  88. .title {
  89. font-weight: bold;
  90. }
  91. }
  92. }

Look at the Sass and note the video and video:hover styles.

They have the following noteworthy characteristics:

video:

  • height, width and margin styles for sizing and spacing of thumbnails
  • float settings to allow the block thumbnails to display as inline, therefore being able to display rows of thumbnails instead of a single column
  • transition specifies that the animation over the thumbnail will take around 1/2 a second to execute
  • figure and figcaption are SASS-enabled nested styles for the image, title and artist video:hover:
  • transform is used to trigger an animation sizing .

2.Use the CSS classes

Edit TunesView.js and add cls and itemClas

  1. cls: 'tunes-view',
  2. itemCls: 'video',

Here’s the code:

  1. Ext.define('ModernTunes.view.TunesView', {
  2. extend: 'Ext.dataview.DataView',
  3. xtype: 'tunesview',
  4. scrollable: true,
  5. cls: 'tunes-view',
  6. layout: {
  7. type: 'box',
  8. pack: 'space-around',
  9. wrap: true
  10. },
  11. itemCls: 'video',
  12. itemTpl: [
  13. '<figure>',
  14. '<div class="thumbnail" style="background-image:url(\'{image}\')"></div>',
  15. '<figcaption><div class=\'title\'>{title}</div><div class=\'artist\'>{artist}</div></figcaption>',
  16. '</figure>'
  17. ]
  18. });

The cls:’tunes-view’ setting represents a class assigned to style the entire view, in this case the background color. The itemCls:’video’ means that the tpl for each item is wrapped in the CSS style video. And when you mouse over an item, the style overvideo is added. You can see that if you look at the DOM.

3.Look at the DOM

Save your changes, and in Chrome right-click on one of the music video images. Choose the “Inspect” context menu option.

Lab: Tunes - Style the View - 图1

Using that menu option opens Chrome’s Developer Tools on the Elements tab. There, you will see that each item contains the

tag and other elements in the tpl. The dataview surrounds each item with a

that contains the itemCls.