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.
#app
.audioplayer(v-for='s in sounddata')
//- label {{s.number}}
audio(v-bind:data-num='s.number' preload="auto")
source(v-bind:src="s.url" type="audio/ogg")
.center_box
h2 Vue.js Piano Project 7
.keyboard
.pianokey(v-for='s in display_keys')
.white(v-if='s.type==\"white\"'
v-on:click='addnote(s.num)'
v-bind:class='get_current_highlight(s.num,s.key)?"playing":""')
.label {{String.fromCharCode(s.key)}}
.black(v-if='s.type==\"black\"'
v-on:click='addnote(s.num)'
v-bind:class='get_current_highlight(s.num,s.key)?"playing":""')
.label {{String.fromCharCode(s.key)}}
br
.controls
ul.notes_list(v-if="notes.length>0")
li(v-for='(note,id) in notes'
v-bind:class="now_note_id-1==id?\"playing\":\"\"")
.num {{note.num}}
.time {{note.time}}
button(v-on:click="load_sample") Sample
button(v-on:click="playnext(1)") Playnext
button(v-if='playing_time<=1'
v-on:click="startplay") Startplay
i.fa.fa-play
button(v-if='playing_time>1'
v-on:click="stopplay") Stopplay
i.fa.fa-pause
button(v-if='record_time<=0'
v-on:click="start_record") Record
i.fa.fa-circle
button(v-if='record_time>=1'
v-on:click="stop_record") StopRecord
i.fa.fa-top
button(v-on:click="notes=[]") Clear
h4 {{playing_time+record_time}}
*
vertical-align: top
font-family: 微軟正黑體
backface-visibility: hidden
$key_width: 44px
$key_height: 300px
$color_white: #eee
$color_black: #585858
@mixin size($w,$h)
width: $w
height: $h
html,body
+size(100%,100%)
margin: 0
padding: 0
h2
margin-bottom: 30px
color: $color_black
button
background-color: transparent
border: none
border: solid 1px
padding: 4px 12px
border-radius: 4px
transition: 0.5s
cursor: pointer
vertical-align: middle
&:hover
background-color: $color_black
color: white
.notes_list
li
display: inline-block
border-right: solid 1px
padding: 2px 5px
cursor: pointer
transition: 0.3s
&:hover
background-color: darken($color_white,5)
&.playing
background-color: darken($color_white,10)
.time
font-size: 8px
opacity: 0.3
.num
font-size: 16px
.center_box
position: absolute
left: 50%
top: 50%
transform: translate(-50%,-50%)
text-align: center
width: 100%
.keyboard
box-shadow: 0px 0px 40px -5px rgba(0,0,0,0.4)
display: inline-block
margin-bottom: 30px
.pianokey
display: inline-block
position: relative
cursor: pointer
.white.playing
background-color: darken($color_white,10)
transform: translate(0px,0px)
.black.playing
background-color: lighten($color_black,10)
transform: translate(0px,0px)
.white
+size($key_width,$key_height)
border: solid 1px $color_white
transform: translate(-3px,-3px)
transition: 0.1s
&:hover
transform: translate(0px,0px)
background-color: $color_white
.black
position: absolute
top: 0px
width: $key_width/2
height: $key_height*0.55
background-color: $color_black
margin-left: -$key_width/4
margin-right: -$key_width/4
z-index: 20
transform: translate(-3px,-3px)
transition: 0.1s
&:hover
transform: translate(0px,0px)
background-color: darken($color_black,10)
.label
position: absolute
color: rgba($color_black,0.5)
bottom: -25px
left: 50%
transform: translate(-50%)
font-size: 8px
i
margin-left: 5px
margin-right: 0px
margin-top: 3px
i.fa-circle
color: darken(red,10)
var soundpack=[];
var soundpack_index=[1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,8,8.5,9,9.5,10,11,11.5,12,12.5,13,13.5,14,15];
for(var i=0;i<soundpack_index.length;i++){
soundpack.push({
number: soundpack_index[i],
url: "https://awiclass.monoame.com/pianosound/set/"+ soundpack_index[i]+".wav"
});
}
var vm = new Vue({
el: "#app",
data: {
sounddata: soundpack,
notes: [{"num":1,"time":150},{"num":1,"time":265},{"num":5,"time":380},{"num":5,"time":501},{"num":6,"time":625},{"num":6,"time":748},{"num":5,"time":871},{"num":4,"time":1126},{"num":4,"time":1247},{"num":3,"time":1365},{"num":3,"time":1477},{"num":2,"time":1597},{"num":2,"time":1714},{"num":1,"time":1837}],
now_note_id: 0,
next_note_id: 0,
playing_time: 0,
record_time: 0,
now_press_key: -1,
player: null,
recorder: null,
display_keys:[
{num: 1,key: 90 ,type:'white'},
{num: 1.5,key: 83 ,type:'black'},
{num: 2,key: 88 ,type:'white'},
{num: 2.5,key: 68 ,type:'black'},
{num: 3,key: 67 ,type:'white'},
{num: 4,key: 86 ,type:'white'},
{num: 4.5,key: 71 ,type:'black'},
{num: 5,key: 66 ,type:'white'},
{num: 5.5,key: 72 ,type:'black'},
{num: 6,key: 78 ,type:'white'},
{num: 6.5,key: 74 ,type:'black'},
{num: 7,key: 77 ,type:'white'},
{num: 8,key: 81 ,type:'white'},
{num: 8.5,key: 50 ,type:'black'},
{num: 9,key: 87 ,type:'white'},
{num: 9.5,key: 51,type:'black'},
{num: 10,key: 69 ,type:'white'},
{num: 11,key: 82 ,type:'white'},
{num: 11.5,key: 53 ,type:'black'},
{num: 12,key: 84 ,type:'white'},
{num: 12.5,key: 54 ,type:'black'},
{num: 13,key: 89 ,type:'white'},
{num: 13.5,key: 55 ,type:'black'},
{num: 14,key: 85 ,type:'white'},
{num: 15,key: 73 ,type:'white'}
]
},
methods: {
playnote: function(id,volume){
if (id>0){
var audio_obj=$("audio[data-num='"+id+"']")[0];
audio_obj.volume=volume;
audio_obj.currentTime=0;
audio_obj.play();
}
},
playnext: function(volume){
var play_note=this.notes[this.now_note_id].num;
console.log(play_note);
this.playnote(play_note,volume);
this.now_note_id+=1;
if (this.now_note_id>=this.notes.length){
this.stopplay();
}
},
start_record: function(){
this.record_time=0;
this.recorder=setInterval(function(){
vm.record_time++;
})
},
stop_record: function(){
clearInterval(this.recorder);
this.record_time=0;
},
startplay: function(){
this.now_note_id=0;
this.playing_time=0;
this.next_note_id=0;
var vobj=this;
this.player=setInterval(function(){
if (vobj.playing_time>=vobj.notes[vobj.next_note_id].time){
vobj.playnext(1);
vobj.next_note_id++;
}
vobj.playing_time++;
},2);
},
stopplay: function(){
clearInterval(this.player);
this.now_note_id=0;
this.playing_time=0;
this.next_note_id=0;
},
get_current_highlight: function(id,skey){
if (this.now_press_key==skey)
return true;
if (this.notes.length==0)
return false
var cur_id=this.now_note_id-1;
if (cur_id<0) cur_id=0;
var num=this.notes[cur_id].num;
if (num==id)
return true;
return false;
},
addnote: function(id){
if (this.record_time>0)
this.notes.push({num: id,time: this.record_time});
this.playnote(id,1);
},
load_sample: function(){
var vobj=this;
$.ajax({
url: "https://awiclass.monoame.com/api/command.php?type=get&name=music_dodoro",
success: function(res){
vobj.notes=JSON.parse(res);
}
});
}
}
});
$(window).keydown(function(e){
var key = e.which;
vm.now_press_key=key;
console.log(key);
for(var i=0;i<vm.display_keys.length;i++){
if (key==vm.display_keys[i].key){
vm.addnote(vm.display_keys[i].num)
}
}
});
$(window).keyup(function(){
vm.now_press_key=-1;
});
Also see: Tab Triggers