Aug
06
2016
0
Revising method for adding drop shadows
After removing the jQuery code for the archives page I reviewed the code I have been adding to the script scripts.js
in order to determine if even more code can be removed and replaced with just CSS. And there was.
The focus this time was on the code I added to add drop shadows to images that are ending with -ds
. Using a selector based on the src
attribute for img
elements it is possible to recreate this feature by just using CSS.
Updated CSS
Old CSS code
/* Dropshadows */
.dropshadow {
box-shadow: 0 0 20px 0 rgba(0,0,0,0.4);
}
Updated CSS code (not the .
after -ds
)
/* Dropshadows */
img[src*="-ds."] {
box-shadow: 0 0 20px 0 rgba(0,0,0,0.4);
}
Removed jQuery code
// Add dropshadow to images ending with `-ds`
$('img').each(function() {
var filename = $(this).attr('src');
var imgName = filename.substr(0, filename.lastIndexOf('.')) || filename;
if ( imgName.substr(imgName.length - 3) == '-ds' ) {
$(this).addClass('dropshadow');
}
});