/
top-ten.js
33 lines (29 loc) · 986 Bytes
/
top-ten.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
( function( $, window ) {
// Removes the `src` from each image. (Madness!)
// Loads the appropriate image for the screen size.
// Determines and sets image widths so they don't rescale when positioned.
function process_card_images() {
$( ".content-card--feature-image" ).each( function() {
var $figure = $( this ),
$image = $figure.find( ".content-card--feature-image-wrapper" ),
$card = $figure.closest( ".content-card" ),
desktop_image = $figure.data( "desktop-image" ),
mobile_image = $figure.data( "mobile-image" );
$image.removeAttr( "src" );
if ( 989 < $( window ).width() && desktop_image ) {
$image.css( {
"background-image": "url(" + desktop_image + ")",
"width": $card.width() / 2
} );
} else if ( mobile_image ) {
$image.css( {
"background-image": "url(" + mobile_image + ")",
"width": "100%"
} );
}
} );
}
$( window ).resize( function() {
process_card_images();
} );
}( jQuery, window ) );