Rx实现拖拽小球重叠覆盖率实时计算效果代码

代码语言:html

所属分类:拖放

代码描述:Rx实现拖拽小球重叠覆盖率实时计算效果代码

代码标签: Rx 拖拽 小球 重叠 覆盖率 实时 计算

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
body {
  padding-top: 15px;
  background-color: #64bbda;
  font-family: 'Quicksand', Arial;
  display: flex;
  justify-content: center;
  user-select: none;
  cursor: default;
  overflow: hidden;
}
.circle {
  top: calc(50% - 75px);
  border-radius: 50%;
  height: 150px;
  width: 150px;
  position: absolute;
}
.circle:hover {
  cursor: grab;
  cursor: -webkit-grab;
  cursor: -moz-grab;
}
#output {
  border-radius: 5px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 1.5em;
  padding: 4px 8px 4px 8px;
  z-index: 0;
}
#one {
  border: 1px solid rgba(0, 0, 0, 0.1);
  background-color: #9fcedf;
  top: calc(60% - 75px);
  left: calc(25% - 75px);
  box-shadow: inset -9px 0px 30px 0 rgba(255, 250, 193, 0), 5px 5px 20px 5px rgba(255, 250, 193, 0);
  z-index: 1;
}
#two {
  background-color: #fff36e;
  top: calc(40% - 75px);
  left: calc(50% - 75px);
  box-shadow: 0 0 20px 5px #fffac1;
  z-index: -1;
}
@keyframes totality {
  from {
    box-shadow: 0 0 20px 5px #fffac1;
  }
  to {
    box-shadow: 0 0 75px 20px #ffffff;
  }
}
#two.totality {
  box-shadow: 0 0 75px 20px #ffffff;
  animation-name: totality;
  animation-duration: 1s;
}
</style>


</head>

<body>
  <div id="output">Coverage: 0%</div>
  <div class="circle draggable" id="two">
  </div>
  <div class="circle draggable" id="one">
  </div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Rx.5.4.3.js"></script>
      <script >
const draggables = document.querySelectorAll('.draggable');
const one = document.getElementById('one');
const two = document.getElementById('two');
const output = document.getElementById('output');

const scale = (low, high, ratio, power = 1) => low + (high - low) * Math.pow(ratio, power);
const descale = (value, low, range) => (value - low) / range;
const bound = (value, low, high) => low !== undefined && value < low ? low : high !== undefined && value > high ? high : value;

const setElementPosition = (element, pos) => {
  const radius = element.clientWidth / 2;
  element.style.left = `${pos.x + pos.offset.x - radius}px`;
  element.style.top = `${pos.y + pos.offset.y - radius}px`;
};

const getMousePos = mouseEvent => ({
  x: mouseEvent.clientX,
  y: mouseEvent.clientY });


const getOffset = (element, pos) => ({
  x: element.offsetLeft + element.clientWidth / 2 - pos.x,
  y: element.offsetTop + element.clientWidth / 2 - pos.y });


const getIntersectArea = (r, d) => d > 2 * r ? 0 :
2 * r * r * Math.acos(0.5 * d / r) -
0.5 * Math.sqrt(Math.pow(2 * r * d, 2) - Math.pow(d, 4));


const getDistance = (posOne, posTwo) => Math.sqrt(
Math.pow(posTwo.x - posOne.x, 2) + Math.pow(posTwo.y - posOne.y, 2));


const scaleRgb = (dark, light, ratio, power = 1) => {
  const red = scale(dark.r, light.r, ratio, power).toFixed(0);
  const green = scale(dark.g, light..........完整代码请登录后点击上方下载按钮下载查看

网友评论0