Skip to content

Instantly share code, notes, and snippets.

@lagagain
Created May 7, 2019 14:03
Show Gist options
  • Save lagagain/c076e6dde72e8294648e1812f6caa205 to your computer and use it in GitHub Desktop.
Save lagagain/c076e6dde72e8294648e1812f6caa205 to your computer and use it in GitHub Desktop.
A simple panter with HTML 5
*{
box-sizing: border-box;
font: bold 14px Arial, sans-serif;
}
html {
height: 100%;
background: white;
background: radial-gradient(circle, #fff 20%, #ccc);
background-size: cover;
}
#calculator {
width: 375px;
height: auto;
margin: 100px auto;
padding: 20px 20px 9px;
background: #9dd2ea;
background: linear-gradient(#9dd2ea, #8bceec);
border-radius: 3px;
box-shadow: 0px 4px #009de4, 0px 10px 15px rgba(0, 0, 0, 0.2);
text-align: center;
}
#calculator .monitor{
height: 40px;
width: 185px;
float: left;
padding: 0 10px;
background: rgba(0, 0, 0, 0.2);
border-radius: 3px;
box-shadow: inset 0px 4px rgba(0, 0, 0, 0.2);
/* Typography */
font-size: 17px;
line-height: 40px;
color: white;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
text-align: right;
letter-spacing: 1px;
}
#calculator .button{
font-size: 1eM;
line-height: 2.5eM;
margin: 0.7ex;
display: inline-block;
width: 3eM;
height: 2.5eM;
user-select: none;
}
#calculator .num{
}
#calculator .operator{
background: #FFF0F5;
margin-right: 0;
}
#calculator .equ{
background: #f1ff92;
box-shadow: 0px 4px #9da853;
color: #888e5f;
}
#calculator .clear{
background: #ff9fa8;
box-shadow: 0px 4px #ff7c87;
color: white;
}
#calculator .num:hover {
background: #9c89f6;
box-shadow: 0px 4px #6b54d3;
color: white;
}
#calculator .equ:hover {
background: #abb850;
box-shadow: 0px 4px #717a33;
color: #ffffff;
}
#calculator .clear:hover {
background: #f68991;
box-shadow: 0px 4px #d3545d;
color: white;
}
#calculator .num:active {
position:relative;
box-shadow: 0px 0px #6b54d3;
top: 4px;
}
#calculator .equ:active {
position:relative;
box-shadow: 0px 0px #717a33;
top: 4px;
}
#calculator .clear:active {
position:relative;
top: 4px;
box-shadow: 0px 0px #d3545d;
}
Copyright (c) 2019, lagagain
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
.button{
//display:inline-block;
//float: left;
//margin:0.7ex;
overflow: hidden;
color: gray;
border-radius: 5px;
background: rgba(193, 255, 248, 0.91);
box-shadow: 2.7px 2.7px 2px rgba(99, 0, 183, 0.88) ;
}
.button:active{
box-shadow: -2.7px -2.7px 2px rgba(99, 0, 183, 0.88) ;
}
.button:hover{
cursor: pointer;
-webkit-box-shadow: 0 1px 41px 10px rgba(189,238,240,0.75);
-moz-box-shadow: 0 1px 41px 10px rgba(189,238,240,0.75);
box-shadow: 0 1px 41px 10px rgba(189,238,240,0.75);
}
var main_nav;
var main_nav_doc;
window.addEventListener('load',function(){
main_nav=window.document.getElementById("main_nav");
main_nav_doc=main_nav.contentDocument;
main_nav_map={
"nav":main_nav_doc.getElementsByTagName('nav'),
"share":main_nav_doc.getElementById("share"),
"home_links":main_nav_doc.getElementsByClassName("home_link"),
}
main_nav_map["nav"][0].onmousemove=function(){
main_nav.style.zIndex="1";
}
main_nav_map["nav"][0].onmouseout=function(){
main_nav.style.zIndex="0";
}
share_a=main_nav_map["share"].getElementsByTagName('a');
for(i=0;i<share_a.length;i++){
share_a[i].href=share_a[i].href+main_nav_map["home_links"][0].href
}
js_parent_drag=window.document.getElementsByClassName('js_parent_drag');
for(i=0;i<js_parent_drag.length;i++){
if(js_parent_drag[i]){
parentBeDraggable(js_parent_drag[i]);
}
}
js_drag=window.document.getElementsByClassName('js_drag');
for(i=0;i<js_drag.length;i++){
if(js_drag[i]){
beDraggable(js_drag[i]);
}
}
js_folder=window.document.getElementsByClassName('js_folder');
for(i=0;i<js_folder.length;i++){
if(js_folder[i]){
folderItem.createNew(js_folder[i],false,true);
}
}
js_open_folder=window.document.getElementsByClassName('js_open_folder');
for(i=0;i<js_open_folder.length;i++){
if(js_open_folder[i]){
folderItem.createNew(js_open_folder[i],true,true);
}
}
}
)
function appendShareBox(e){
share_box=document.createElement("div");
share_box.setAttribute("id","share_box");
close_img=document.createElement("img");
close_img.className="close_img";
close_img.src="/img/close.svg";
share_frame=document.createElement("iframe");
share_frame.setAttribute("name","sharebox");
share_box.appendChild(share_frame);
e.appendChild(share_box);
return share_box;
}
/*url是圖片位置,e是使用物件*/
function cursorPicture(url,e){
img=document.createElement("img");
img.src=url;
img.style.position="fixed";
img.style.margin="0";
img.style.padding="0";
e.appendChild(img);
e.addEventListener("mousemove",function(event){
if(event.clientX){
x=event.clientX;
y=event.clientY;
}else{
x=event.x;
y=event.y;
}
img.style.top=(y+5)+"px";
img.style.left=(x+5)+"px";
}
)
}
var draggableItem={
createNew:function(e){
var newDraggableItem={
item:e,
/*此為事件觸發的函式*/
changPos:function (event){
if(event.clientX){
x=event.clientX;
y=event.clientY;
}else{
x=event.x;
y=event.y;
}
newDraggableItem.item.style.top=y-10+"px";
newDraggableItem.item.style.left=x-10+"px";
},
elementWithMouse:function (){
newDraggableItem.item.style.position="fixed";
newDraggableItem.item.style.zIndex="5";
window.addEventListener('mousemove',newDraggableItem.changPos);
},
elementNotWithMouse:function(){
window.removeEventListener('mousemove',newDraggableItem.changPos);
newDraggableItem.item.style.zIndex="auto";
},
};
newDraggableItem.item.addEventListener('mousedown',newDraggableItem.elementWithMouse);
newDraggableItem.item.addEventListener('mouseup',newDraggableItem.elementNotWithMouse);
newDraggableItem.removeThis=function(){
newDraggableItem.item.removeEventListener('mousedown',newDraggableItem.elementWithMouse);
newDraggableItem.item.removeEventListener('mouseup',newDraggableItem.elementNotWithMouse);
}
newDraggableItem.item.addEventListener('mousemove',function(){
newDraggableItem.item.style.cursor="move";
}
)
newDraggableItem.item.addEventListener('mouseout',function(){
newDraggableItem.item.style.cursor="default";
}
)
return newDraggableItem;
}
}
function beDraggable(e) {
draggableItem.createNew(e);
}
function parentBeDraggable(e){
parent=e.parentNode;
e.addEventListener('mousedown',function(){
parent=beDraggable(parent);
}
);
e.addEventListener('mouseup',parent.removeThis());
}
var folderItem={
createNew:function(e,s,h){
var newFolderItem={
item:e,
status:s,
hl:h,
}
newFolderItem.header=newFolderItem.item.getElementsByTagName('header')[0];
newFolderItem.footer=newFolderItem.item.getElementsByTagName('footer')[0];
newFolderItem.body=newFolderItem.item.getElementsByTagName('article')[0];
if(newFolderItem.body){
newFolderItem.body.style.cssText="transition: all 2s;overflow:hidden;overflow:auto";
newFolderItem.o_height=newFolderItem.body.clientHeight;
newFolderItem.o_width=newFolderItem.body.clientWidth;
}
if(!newFolderItem.status){
if(newFolderItem.hl){
newFolderItem.body.style.maxHeight="0px";
}else{
newFolderItem.body.style.maxWidth="0px";
}
}
newFolderItem.header.addEventListener('click',function(){
if(newFolderItem.hl){
if(newFolderItem.status){
newFolderItem.body.style.maxHeight="0px";
newFolderItem.status=false;
}else{
//newFolderItem.body.style.height=newFolderItem.o_height+"px";
newFolderItem.body.style.maxHeight="80rem";
newFolderItem.status=true;
}
}else{
if(newFolderItem.status){
newFolderItem.body.style.maxWidth="0px";
newFolderItem.status=false;
}else{
newFolderItem.body.style.maxWidth="80rem";
newFolderItem.status=true;
}
}
}
)
newFolderItem.header.addEventListener('mousemove',function(){
newFolderItem.header.style.cursor="pointer";
}
)
newFolderItem.header.addEventListener('mouseout',function(){
newFolderItem.header.style.cursor="default";
}
)
return newFolderItem;
}
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>小畫家</title>
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="calculator.css" />
<script type="text/javascript" src="main.js"></script>
</head>
<style>
#main_body{
background: none;
width:100%;
height:100%;
}
body{
width:100%;
height:80%;
padding:0;
margin:0;
top:0;
}
</style>
<body>
<article id="main_body" class="clearfix">
</article>
</body>
<script type="text/javascript">
cursorPicture('img/playstation-circle-icon.png',document.body);
main_body=document.getElementById('main_body');
var status=false;
main_body.addEventListener('click',function(event){
//alert('test');
var img=document.createElement("img");
img.src='img/playstation-circle-icon.png';
img.style.position="absolute";
img.style.margin="0";
img.style.padding="0";
main_body.appendChild(img);
if(event.clientX){
x=event.clientX;
y=event.clientY;
}else{
x=event.x;
y=event.y;
}
img.style.top=(y-150)+"px";
img.style.left=(x-40)+"px";
}
)
main_body.addEventListener('mousedown',function(){status=true});
main_body.addEventListener('mouseup',function(){status=false});
main_body.addEventListener('mousemove',function(event){
if(status){
//alert('test');
var img=document.createElement("img");
img.src='img/playstation-circle-icon.png';
img.style.position="absolute";
img.style.margin="0";
img.style.padding="0";
main_body.appendChild(img);
if(event.clientX){
x=event.clientX;
y=event.clientY;
}else{
x=event.x;
y=event.y;
}
img.style.top=(y-150)+"px";
img.style.left=(x-40)+"px";
}
}
);
</script>
</html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment