Last active
August 29, 2015 14:18
-
-
Save jnsdbr/2d3a3108815d7bfb1186 to your computer and use it in GitHub Desktop.
Fix subpixel rendering errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fixSubPixel = function(container, elements) { | |
// Default columns | |
var cols = 2; | |
// Columns according to mediaqueries | |
if(container.width() > 1023) | |
{ | |
cols = 4; | |
} | |
if(container.width() > 1281) | |
{ | |
cols = 5; | |
} | |
if(container.width() > 1900) | |
{ | |
cols = 6; | |
} | |
// Check if container has uneven width | |
if(container.width() % 2 !== 0) | |
{ | |
// Calculations | |
var itemWidth = Math.floor(container.width() / cols); | |
var remainder = container.width() % itemWidth; | |
var curRemainder = rest; | |
var itemHeight = itemWidth + 1; | |
var counter = 0; | |
elements.each(function(index) { | |
var tmpWidth = itemWidth; | |
if(curRemainder > 0) | |
{ | |
tmpWidth += 1; | |
curRemainder--; | |
} | |
$(this).css({ | |
'width': tmpWidth + 'px', | |
'height': itemHeight + 'px' | |
}); | |
$(this).children('a').children('img').css({ | |
'width': tmpWidth + 'px', | |
'height': itemHeight + 'px' | |
}); | |
counter++; | |
if(counter == cols) | |
{ | |
curRemainder = remainder; | |
counter = 0; | |
} | |
}); | |
} | |
else | |
{ | |
elements.each(function(index) { | |
$(this).css({ | |
'width': 100 / cols + '%', | |
'height': '' | |
}); | |
$(this).children('a').children('img').css({ | |
'width': '100%', | |
'height': 'auto' | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment