js滚动检测目标元素是否在可视范围内

代码语言:html

所属分类:游戏

代码描述:js滚动检测目标元素是否在可视范围内

代码标签: 目标 元素 是否 可视 范围内

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


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
.box,
pre {
  width: 100%;
  max-width: 412px;
  border-radius: 8px;
}

.box {
  background: #fff;
  border: 2px solid #D1D6EE;
  position: relative;
  margin-bottom: 16px;
}
.box .scroll {
  height: 200px;
  padding: 20px;
  overflow: auto;
}
.box .scroll > div {
  height: 300%;
}
.box .scroll > div .target {
  margin-top: 100%;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
  background: #275EFE;
  color: #fff;
  border-radius: 6px;
}
.box span {
  display: block;
  position: absolute;
  text-align: center;
  color: #646B8C;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 14px;
  padding: 8px 0;
}
.box span strong {
  font-weight: bold;
  color: #2B3044;
}

pre {
  background: #1A1E32;
  padding: 20px;
}
pre code {
  font-family: 'Fira Mono';
  color: #BBC1E1;
  line-height: 1.4;
  font-size: 12px;
}
pre code .token.function {
  color: #5C86FF;
}
pre code .token.string {
  color: #CB7DD0;
}
pre code .token.parameter {
  color: #C4DDB2;
}
pre code .token.class-name {
  color: #E2C484;
}
pre code .token.keyword {
  color: #F9FFB1;
}
pre code .token.comment {
  opacity: .6;
}

body {
  font-family: 'Roboto', Arial;
  min-height: 100vh;
  background: #F6F8.........完整代码请登录后点击上方下载按钮下载查看

网友评论0