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 URLs 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 its URL and the proper URL extension.
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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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 lang="ja">
<head>
<meta charset="UTF-8">
<title>Canvasの学習</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="css/mycanvas.css" rel="stylesheet" type="text/css">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body id="main">
<canvas id="mycanvas">
Canvasに対応したブラウザを使ってください。
</canvas>
<script src="js/myscript02.js"></script>
</body>
</html>
@charset "utf-8";
html,body{
height:100%;
}
canvas{
display:block;
width:100%;
height:100%;
background:rgba(204,204,204,0.2);
}
/*
1.ブラウザ全体にカンバスを描写
2.マウスオーバーすると中心点からマウスまで1本の線
マウスオーバーするとマウスからブラウザ端までの線のアニメーション。
3.ブラウザサイズ変更の度にカンバスのサイズを変更
*/
var width;//ブラウザ幅
var height;//ブラウザ高
var element;
var canvas;
var ctx;
var mouseX;
var mouseY;
//線の本数
var lines = 20;
//ブラウザの中心から頂点までを半径とした円周上の点の座標
var endPX = new Array;
var endPY = new Array;
var radius;
var angle = new Array;
var angleSpeed = 0.2;
var angleSize = new Array;
var frame = 0;
function windowSize(){
width = $('.canvas-wrapper').width();
height = $('.canvas-wrapper').height();
}
window.onload = function(){
//canvasを全画面で描写
windowSize();
$( '#mycanvas' ).get( 0 ).width = width;
$( '#mycanvas' ).get( 0 ).height = height;
mouseX = width/2;
mouseY = height/2;
for(var i = 0;i < lines;i++){
endPX[i] = 0;
endPY[i] = 0;
angle[i] = i / 6;
if(i == 0 || i == lines - 1){
angleSize[i] = angleSpeed;
}else{
angleSize[i] = angleSpeed + 0.1;
}
}
//ブラウザの対角線の長さを半径とする
radius = Math.ceil(Math.sqrt(Math.pow(width,2) + Math.pow(height,2)));
// 各エレメントを取得
element = document.getElementById("mycanvas");
mouseEvent();
canvas = document.getElementById('mycanvas');
if(!canvas || !canvas.getContext) return false;
ctx = canvas.getContext('2d');
}
window.onresize=function(){
//canvasを全画面で描写
windowSize();
//ブラウザの対角線の長さを半径とする
radius = Math.ceil(Math.sqrt(Math.pow(width,2) + Math.pow(height,2)));
$( '#mycanvas' ).get( 0 ).width = $( window ).width();
$( '#mycanvas' ).get( 0 ).height = $( window ).height();
}
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();
function loop(){
requestAnimFrame(loop);
frame++;
if(frame > 60) frame = 0;
//カンバスのリセット
ctx.clearRect(0,0,width,height);
drawLineCenter();
drawLineWindow();
}
function drawLineCenter(){
ctx.clearRect(0,0,width,height);
//直線の描写の開始宣言
ctx.beginPath();
//直線の最初の点
ctx.moveTo(width/2,height/2);
ctx.strokeStyle = 'rgb(0,0,0)';
//線を引く
ctx.lineTo(mouseX,mouseY);
ctx.lineWidth = 0.1;
ctx.stroke();
}
function drawLineWindow(){
//直線の描写の開始宣言
for(var i = 0;i < lines;i++){
ctx.beginPath();
ctx.lineWidth = 0.1;
//直線の最初の点
ctx.moveTo(mouseX,mouseY);
if(i == 0 || i == lines - 1){
ctx.strokeStyle = 'rgba(192, 80, 77, 0)';
}else{
ctx.strokeStyle = 'rgb(0,0,0)';
}
//線を引く
ctx.lineTo(endPX[i],endPY[i]);
ctx.stroke();
endPX[i] = Math.cos(Math.PI / 180 * angle[i]) * radius + mouseX;
endPY[i] = Math.sin(Math.PI / 180 * angle[i]) * radius + mouseY;
if(true) {
//先頭と一番後ろは判定用
if(i == 0 || i == lines - 1){
angle[i] += angleSize[i];
}else{
//一番後ろ以下の角度になったとき加速
if(angle[0] > angle[i]){
angleSize[i] = angleSpeed + 0.1;
//先頭以上の角度になったとき減速
}else if(angle[i] > angle[lines - 1]){
angleSize[i] = angleSpeed - 0.1;
}
angle[i] += angleSize[i];
}
} else {
// 角度を0に戻す
//angle[i] = 0;
}
}
console.log(angleSize[10]);
}
function mouseEvent(){
function MouseOverFunc(e){
loop();
}
function MouseMoveFunc(e){
mouseX = e.pageX;
mouseY = e.pageY;
}
function MouseOutFunc(e){
}
// ------------------------------------------------------------
// イベントのリッスンを開始する
// ------------------------------------------------------------
// イベントリスナーに対応している
if(element.addEventListener){
// マウスオーバー時に実行されるイベント
element.addEventListener("mouseover" , MouseOverFunc);
// マウスカーソルが移動するたびに実行されるイベント
element.addEventListener("mousemove" , MouseMoveFunc);
// マウスアウト時に実行されるイベント
element.addEventListener("mouseout" , MouseOutFunc);
// アタッチイベントに対応している
}else if(element.attachEvent){
// マウスオーバー時に実行されるイベント
element.attachEvent("onmouseover" , MouseOverFunc);
// マウスカーソルが移動するたびに実行されるイベント
element.attachEvent("onmousemove" , MouseMoveFunc);
// マウスアウト時に実行されるイベント
element.attachEvent("onmouseout" , MouseOutFunc);
}
}
Also see: Tab Triggers