Skip to content

Instantly share code, notes, and snippets.

@lasershow
Created January 26, 2016 16:17
Show Gist options
  • Save lasershow/914e4fee72bf831288f4 to your computer and use it in GitHub Desktop.
Save lasershow/914e4fee72bf831288f4 to your computer and use it in GitHub Desktop.
jquery.tile.jsをrails + coffeeで使用する方法 ref: http://qiita.com/lasershow/items/20393fa26cabee974672
(function($) {
$.fn.tile = function(columns) {
var tiles, $tile, max, c, h, remove, s = document.body.style, a = ["height"],
last = this.length - 1;
if(!columns) columns = this.length;
remove = s.removeProperty ? s.removeProperty : s.removeAttribute;
return this.each(function() {
remove.apply(this.style, a);
}).each(function(i) {
c = i % columns;
if(c == 0) tiles = [];
$tile = tiles[c] = $(this);
h = ($tile.css("box-sizing") == "border-box") ? $tile.outerHeight() : $tile.innerHeight();
if(c == 0 || h > max) max = h;
if(i == last || c == columns - 1) {
$.each(tiles, function() { this.css("height", max); });
}
});
};
})(jQuery);
$ ->
$('任意のクラス名').tile()
$ ->
$('任意のクラス名').tile(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment