javascript 标题//来源https://jsbin.com/zugekoy Posted 2021-05-03
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 标题//来源https://jsbin.com/zugekoy相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MakeDraggable</title>
<link rel="stylesheet" href="draganddrop.css">
<script src="draganddrop.js" defer></script>
<style id="jsbin-css">
@import "../../Common/common.css";
.sq{
position: absolute;
width: 150px; height: 150px; top: 100px; left:100px;
background-color: red;
}
</style>
</head>
<body>
<div id="dad" class="sq" tabindex="-1"></div>
<script id="jsbin-javascript">
function makeDraggable(elem){
elem.addEventListener("mousedown", function(event1){
let left0 = elem.offsetLeft;
let top0 = elem.offsetTop;
let x0 = event1.clientX;
let y0 = event1.clientY;
document.addEventListener("mousemove", mmove);
document.addEventListener("mouseup", mup);
function mmove(event2){
let x = event2.clientX;
let y = event2.clientY;
elem.style.left = left0 + (x -x0) + "px";
elem.style.top = top0 + (y -y0) + "px";
}
function mup(){
document.removeEventListener("mousemove", mmove);
document.removeEventListener("mouseup", mup);
}
})
}
makeDraggable(dad);
dad.addEventListener("keydown",function(e){
let keyCode = e.key;
switch(keyCode){
case "r":
case "R": dad.style.backgroundColor="red"; break;
case "g":
case "G": dad.style.backgroundColor="green"; break;
case "b":
case "B": dad.style.backgroundColor="blue";break;
case "y":
case "Y": dad.style.backgroundColor="yellow";
}
})
</script>
<script id="jsbin-source-css" type="text/css">@import "../../Common/common.css";
.sq{
position: absolute;
width: 150px; height: 150px; top: 100px; left:100px;
background-color: red;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">function makeDraggable(elem){
elem.addEventListener("mousedown", function(event1){
let left0 = elem.offsetLeft;
let top0 = elem.offsetTop;
let x0 = event1.clientX;
let y0 = event1.clientY;
document.addEventListener("mousemove", mmove);
document.addEventListener("mouseup", mup);
function mmove(event2){
let x = event2.clientX;
let y = event2.clientY;
elem.style.left = left0 + (x -x0) + "px";
elem.style.top = top0 + (y -y0) + "px";
}
function mup(){
document.removeEventListener("mousemove", mmove);
document.removeEventListener("mouseup", mup);
}
})
}
makeDraggable(dad);
dad.addEventListener("keydown",function(e){
let keyCode = e.key;
switch(keyCode){
case "r":
case "R": dad.style.backgroundColor="red"; break;
case "g":
case "G": dad.style.backgroundColor="green"; break;
case "b":
case "B": dad.style.backgroundColor="blue";break;
case "y":
case "Y": dad.style.backgroundColor="yellow";
}
})</script></body>
</html>
@import "../../Common/common.css";
.sq{
position: absolute;
width: 150px; height: 150px; top: 100px; left:100px;
background-color: red;
}
function makeDraggable(elem){
elem.addEventListener("mousedown", function(event1){
let left0 = elem.offsetLeft;
let top0 = elem.offsetTop;
let x0 = event1.clientX;
let y0 = event1.clientY;
document.addEventListener("mousemove", mmove);
document.addEventListener("mouseup", mup);
function mmove(event2){
let x = event2.clientX;
let y = event2.clientY;
elem.style.left = left0 + (x -x0) + "px";
elem.style.top = top0 + (y -y0) + "px";
}
function mup(){
document.removeEventListener("mousemove", mmove);
document.removeEventListener("mouseup", mup);
}
})
}
makeDraggable(dad);
dad.addEventListener("keydown",function(e){
let keyCode = e.key;
switch(keyCode){
case "r":
case "R": dad.style.backgroundColor="red"; break;
case "g":
case "G": dad.style.backgroundColor="green"; break;
case "b":
case "B": dad.style.backgroundColor="blue";break;
case "y":
case "Y": dad.style.backgroundColor="yellow";
}
})
以上是关于javascript 标题//来源https://jsbin.com/zugekoy的主要内容,如果未能解决你的问题,请参考以下文章
chrome 上的 javascript 错误 :: 阻止了来源为“https://tpc.googlesyndication.com”的框架 [重复]
javascript //来源https://jsbin.com
javascript JS Bin //来源https://jsbin.com/kanukob
html javascript在.Rmd中呈现推文。资料来源:https://dev.twitter.com/web/javascript/loading
Yammer JavaScript SDK -“访问控制允许来源”问题
JavaScript 跨域调用:从 HTTP 调用到 HTTPS