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.
.tunes-view {
background-color: #eeeeee;
-webkit-transition: -webkit-filter 250ms;
transition: -webkit-filter 250ms;
-o-transition: filter 250ms;
-moz-transition: filter 250ms;
transition: filter 250ms;
transition: filter 250ms, -webkit-filter 250ms;
}
.blur .tunes-view {
-webkit-filter: blur(5px) grayscale(80%);
filter: blur(5px) grayscale(80%);
}
.video:hover {
-webkit-transform: scale(1.10);
-moz-transform: scale(1.10);
-o-transform: scale(1.10);
transform: scale(1.10);
box-shadow: 2px 2px 10px rgba(0,0,0,.2);
.thumbnail {
-webkit-filter: none;
filter: none;
}
}
.video {
-webkit-transition: transform 500ms ease;
-moz-transition: transform 200ms ease;
-o-transition: transform 200ms ease;
-webkit-transition: -webkit-transform 200ms ease;
transition: -webkit-transform 200ms ease;
-o-transition: -o-transform 200ms ease;
-moz-transition: transform 200ms ease, -moz-transform 200ms ease;
transition: transform 200ms ease;
transition: transform 200ms ease, -webkit-transform 200ms ease, -moz-transform 200ms ease, -o-transform 200ms ease;
width: 16vw;
height: 16vw;
text-align: center;
background: #fff;
color: #777;
margin: 1.2vw;
cursor: pointer;
.thumbnail {
width: 100%;
height: 100%;
background-size: cover;
-webkit-transition: -webkit-filter 300ms;
transition: -webkit-filter 300ms;
-o-transition: filter 300ms;
-moz-transition: filter 300ms;
transition: filter 300ms;
transition: filter 300ms, -webkit-filter 300ms;
-webkit-filter: grayscale(80%);
filter: grayscale(80%);
}
figure {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-moz-box-orient: vertical;
-moz-box-direction: normal;
flex-direction: column;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
align-items: center;
height: 100%;
margin: 0;
}
figcaption {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
padding: .25vw 1vw;
font-size: 1.1vw;
overflow: hidden;
background-color: rgba(0,0,0, .5);
color: white;
.title, .artist {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.title {
font-weight: bold;
}
}
}
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
cls: 'tunes-view',
itemCls: 'video',
Here’s the code:
Ext.define('ModernTunes.view.TunesView', {
extend: 'Ext.dataview.DataView',
xtype: 'tunesview',
scrollable: true,
cls: 'tunes-view',
layout: {
type: 'box',
pack: 'space-around',
wrap: true
},
itemCls: 'video',
itemTpl: [
'<figure>',
'<div class="thumbnail" style="background-image:url(\'{image}\')"></div>',
'<figcaption><div class=\'title\'>{title}</div><div class=\'artist\'>{artist}</div></figcaption>',
'</figure>'
]
});
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.
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.