HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<html>
<head>
<meta charset="utf-8"/>
<script type="application/javascript">
</script>
<style type = "application/CSS"></style>
</head>
<body onload="draw(1);">
<canvas id="canvas" width="150" height="150"></canvas>
<div class="introduce">二色を混ぜて<br/>吹き出しの色を作れ!</div>
<div class="circle num1"></div>
<div class="circle num2"></div>
<div class="circle num3"></div>
<div class="circle num4"></div>
<div class="circle num5"></div>
<div class="circle num6"></div>
<div class="circle num7"></div>
<div class="circle num8"></div>
<div class="circle num9"></div>
<div class="circle num10"></div>
<div class="circle num11"></div>
<div class="circle num12"></div>
<div class="circle num13"></div>
<div class="circle num14"></div>
<div class="circle num15"></div>
<div class="circle answer"></div>
<br/>
<button class = "level 1" onClick = "draw(1);">初級</button>
<button class = "level 2" onclick = "draw(2);">中級</button>
<button class = "level 3" onclick = "draw(3);">上級</button>
</body>
</html>
.circle{
position:absolute;
width: 50px;
height: 50px;
border-radius: 50%;
visibility: hidden;
transition-property: top,left;
transition-duration:500;
transition-timing-function:linear;
}
.circle.num1{
top: 320px;
left: 10px;
background-color: #ff0000;
}
.circle.num2{
top: 320px;
left: 70px;
background-color: #ff0000;
}
.circle.num3{
top: 320px;
left: 130px;
background-color: #ff0000;
}
.circle.num4{
top: 320px;
left: 190px;
background-color: #ff0000;
}
.circle.num5{
top: 320px;
left: 250px;
background-color: #ff0000;
}
.circle.num6{
top: 380px;
left: 10px;
background-color: #ff0000;
}
.circle.num7{
top: 380px;
left: 70px;
background-color: #ff0000;
}
.circle.num8{
top: 380px;
left: 130px;
background-color: #ff0000;
}
.circle.num9{
top: 380px;
left: 190px;
background-color: #ff0000;
}
.circle.num10{
top: 380px;
left: 250px;
background-color: #ff0000;
}
.circle.num11{
top: 440px;
left: 10px;
background-color: #ff0000;
}
.circle.num12{
top: 440px;
left: 70px;
background-color: #ff0000;
}
.circle.num13{
top: 440px;
left: 130px;
background-color: #ff0000;
}
.circle.num14{
top: 440px;
left: 190px;
background-color: #ff0000;
}
.circle.num15{
top: 440px;
left: 250px;
background-color: #ff0000;
}
.circle.answer{
top: 50px;
left: 230px;
background-color: #ffffff;
}
.introduce{
font-size: 150%;
font-weight: bold;
color: #fff;
text-shadow:
0px 0px 1px #666,
0px 0px 5px #666,
0px 0px 6px #666;
}
.level{
border:solid 1px #ccc;
padding:10px 25px;
margin:0 0 20px;
font-family:Arial, sans-serif;
font-size:1.2em;
text-transform:uppercase;
font-weight:bold;
color:#333;
cursor:pointer;
}
.level:hover{
color: #ff0000;
}
.score
{
position:absolute;
top: 160px;
left: 200px;
font-size: 150%;
font-weight: bold;
visibility: hidden;
}
.score.Good
{
}
function draw(level) {
$(".circle").off();
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
//仮吹出
fuki(ctx);
var StoneNum=LvChoice(level);
//問題玉生成
makeStone(StoneNum);
//正解生成
var ritCo = makeRight(ctx);
//回答作成
var aEnd = answer(ritCo,level);
}
}
function LvChoice(level){
if(level == 1) return 5;
if(level == 2) return 10;
if(level == 3) return 15;
}
function makeStone(level){
for(var i=1; i<16; i++){
$(".circle.num"+i).css("visibility","hidden");
}
for(var i=1; i<level+1; i++){
var r = Math.floor(Math.random()*255);
var g = Math.floor(Math.random()*255);
var b = Math.floor(Math.random()*255);
$(".circle.num"+i).css( 'background-color',"rgb("+ r +','+ g + ',' + b +')');
$(".circle.num"+i).css("visibility","visible");
}
}
function makeRight(ctx){
//2色ランダムピック1
var cPic1 = Math.floor(Math.random()*4)+1;
var color1 = $(".circle.num"+cPic1).css("background-color");
$("#pic1").html("<br/>"+"I have a <span style='color:" +
color1 + ";'>" + color1 + "</span>.");
//背景色の余計な文字列削除
color1 = color1.replace("rgb(","");
color1 = color1.replace(")","");
//文字列分割
color1 = color1.split(",");
console.log(color1);
//2色ランダムピック2
do
var cPic2 = Math.floor(Math.random()*4)+1;
while(cPic1 == cPic2);
var color2 = $(".circle.num"+cPic2).css("background-color");
$("#pic2").html("<br/>"+"I have a <span style='color:" +
color2 + ";'>" + color2 + "</span>.");
//背景色の余計な文字列削除
color2 = color2.replace("rgb(","");
color2 = color2.replace(")","");
//文字列分割
color2 = color2.split(",");
console.log(color2);
var cRight = color1;
cRight[0] = Math.floor((parseInt(color1[0])+parseInt(color2[0]))/2);
cRight[1] = Math.floor((parseInt(color1[1])+parseInt(color2[1]))/2);
cRight[2] = Math.floor((parseInt(color1[2])+parseInt(color2[2]))/2);
console.log(cRight);
//玉色生成
var r = cRight[0];
var g = cRight[1];
var b = cRight[2];
//お手本玉
ctx.beginPath();
ctx.fillStyle = "rgb("+ r +','+ g + ',' + b +')';
ctx.arc(77,63,18,0,Math.PI*2,true);
ctx.fill();
return cRight;
}
function fuki(ctx){
ctx.beginPath();
ctx.moveTo(75,25);
ctx.quadraticCurveTo(25,25,25,62.5);
ctx.quadraticCurveTo(25,100,80,100);
ctx.quadraticCurveTo(50,120,50,125);
ctx.quadraticCurveTo(60,120,100,100);
ctx.quadraticCurveTo(125,90,125,62.5);
ctx.quadraticCurveTo(125,25,75,25);
ctx.stroke();
}
function answer(ritCo,Lv){
/*回答作成*/
var pic1f=0;
var c1buf = [];
var colbuf = [];
//玉から2色とる
$(".circle").on("click", function () {
if(pic1f == 0){
var color1 = $(this).css("background-color");
//背景色の余計な文字列削除
color1 = color1.replace("rgb(","");
color1 = color1.replace(")","");
//文字列分割
color1 = color1.split(",");
$(this).animate({
'left': '230px',
'top': '50px'
},{
'duration': 100
});
//10進数を16進数に変換して連結
var color = "#"
+("0" + parseInt(color1[0]).toString(16)).slice(-2)
+("0" + parseInt(color1[1]).toString(16)).slice(-2)
+("0" + parseInt(color1[2]).toString(16)).slice(-2);
pic1f = 1;
c1buf = color1;
$(".circle.answer").css( 'background-color',color);
}else{
var color2 = $(this).css("background-color");
//背景色の余計な文字列削除
color2 = color2.replace("rgb(","");
color2 = color2.replace(")","");
//文字列分割
color2 = color2.split(",");
var color1 = c1buf;
//混色
var cAns = [];
cAns[0] = Math.floor((parseInt(color1[0])+parseInt(color2[0]))/2);
cAns[1] = Math.floor((parseInt(color1[1])+parseInt(color2[1]))/2);
cAns[2] = Math.floor((parseInt(color1[2])+parseInt(color2[2]))/2);
pic1f = 0;
$(this).animate({
'left': '230px',
'top': '50px'
},{
'duration': 100
});
colbuf=cAns;
cAns = "#"
+("0" + parseInt(cAns[0]).toString(16)).slice(-2)
+("0" + parseInt(cAns[1]).toString(16)).slice(-2)
+("0" + parseInt(cAns[2]).toString(16)).slice(-2);
$(".circle.answer").css( 'background-color',cAns);
$(".circle.answer").css( "visibility","visible");
/*評価*/
judge(ritCo,colbuf,Lv);
}
});
}
function judge(ritCo,ansCo,level){
var errors = 0;
//誤差の和を出す
errors = Math.abs(parseInt(ritCo[0]) - parseInt(ansCo[0]))
+ Math.abs(parseInt(ritCo[1]) - parseInt(ansCo[1]))
+ Math.abs(parseInt(ritCo[2]) - parseInt(ansCo[2]));
console.log("errors "+ errors);
var border;
if(level == 1) border = 100;
if(level == 2) border = 60;
if(level == 3) border = 30;
console.log("border "+ border);
if(errors>=0 && errors <= 10){
setTimeout("Good();",1300);
}else if(errors>=11 && errors <= border){
setTimeout("Better();",1300);
}else{
setTimeout("Bad();",1300);
}
return 1;
}
function Good(){
alert("Good");
location.reload(true);
}
function Better(){
alert("Better");
location.reload(true);
}
function Bad(){
alert("Bad");
location.reload(true);
}
Also see: Tab Triggers