Created
January 26, 2016 16:17
-
-
Save lasershow/914e4fee72bf831288f4 to your computer and use it in GitHub Desktop.
jquery.tile.jsをrails + coffeeで使用する方法 ref: http://qiita.com/lasershow/items/20393fa26cabee974672
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
(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); |
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
$ -> | |
$('任意のクラス名').tile() |
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
$ -> | |
$('任意のクラス名').tile(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment