Created
January 5, 2012 05:57
-
-
Save kobakei/1563931 to your computer and use it in GitHub Desktop.
文字列を虹色に表示するスクリプト
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Rainbow</title> | |
<!-- jQuery --> | |
<script type="text/javascript" src="http://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load("jquery", "1"); | |
</script> | |
<!-- rainbow.js --> | |
<script type="text/javascript" src="/javascripts/rainbow.js"></script> | |
</head> | |
<body> | |
<h1 class="rainbow">ここに書いた文字が虹色に表示されます。</h1> | |
<p class="rainbow">ここに書いた文字が虹色に表示されます。</p> | |
</body> | |
</html> |
This file contains hidden or 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
/** | |
* rainbow.js | |
* Copyright Keisuke Kobayashi 2012 | |
*/ | |
$(document).ready(function(){ | |
var COLORS = [ | |
'red', 'orange', 'yellow', 'green', 'blue', 'navy', 'purple' | |
]; | |
var doms = $('.rainbow'); | |
doms.each(function (index) { | |
var text = $(this).text(); | |
var html = ""; | |
for (var i = 0; i < text.length; i++) { | |
html += "<span style='color: " + COLORS[i % COLORS.length] + "'>" + text[i] + "</span>"; | |
} | |
$(this).html(html); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment