<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<style type="text/css">
#message1 {
text-align: center;
vertical-align: middle;
color: #ffffff;
background-color: #ff0000;
width: 100px;
height: 50px;
position: absolute;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
這些是一些文字<br>這些是一些文字<br>這些是一些文字<br>
<button>其他元件</button>
<div id="message1">
看點廣告吧!<br><br>
<button id="confirm">確定</button>
</div>
<script type="text/javascript">
function style(elem, prop) {
return window.getComputedStyle(elem, null)[prop];
}
// value 未指定時,用來取得不透明度
function opacity(elem, value) {
if(value === undefined) {
let opt = style(elem, 'opacity');
return opt === '' ? 1 : parseFloat(opt);
} else {
elem.style.opacity = value;
}
}
class Dimension {
static screen() {
return {
width: screen.width,
height: screen.height
};
}
static screenAvail() {
return {
width: screen.availWidth,
height: screen.availHeight
};
}
static browser() {
return {
width: window.outerWidth,
height: window.outerHeight
};
}
static html() {
return {
width: window.documentElement.scrollWidth,
height: window.documentElement.scrollHeight
};
}
static body() {
return {
width: window.body.scrollWidth,
height: window.body.scrollHeight
};
}
static viewport() {
return {
width: window.innerWidth,
height: window.innerHeight
};
}
}
class Coordinate {
static browser() {
return {
x: window.screenX,
y: window.screenY
};
}
static scroll() {
return {
x: window.pageXOffset,
y: window.pageYOffset
};
}
}
let message1 = document.getElementById('message1');
opacity(message1, 0.5);
let {width, height} = Dimension.viewport();
message1.style.width = `${width}px`;
message1.style.paddingTop = `${height / 2}px`;
message1.style.height = `${height / 2}px`;
document.getElementById('confirm').onclick = function() {
message1.style.width = '0px';
message1.style.height = '0px';
message1.style.paddingTop = '0px';
message1.style.display = 'none';
};
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |