1 Star 0 Fork 0

夕空/scrolldrag

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index2.html 4.11 KB
一键复制 编辑 原始数据 按行查看 历史
夕空 提交于 2022-11-03 10:48 . 首次提交
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta charset="UTF-8">
<script src="js/touchDrag.js"></script>
<title></title>
<style>
html,body{margin: 0;padding: 0;width: 100%;height: 100%;}
.scrollease{transition: all 0.3s cubic-bezier(0,1,1,1);}
.main{
width: 100%;
height: 100%;
/* 用户自己滚动 */
overflow: auto;
-webkit-overflow-scrolling: touch;
}
.wrap {
width: 100%; height: 100%;
/*弹性盒子*/
display: -webkit-box;
display: -webkit-flex;
display: flex;
/*从上向下垂直排列子元素。*/
-webkit-box-orient: vertical;
-webkit-flex-flow: column;
flex-flow: column;
}
.wrap >dl {
flex:0 0 100%;
position: relative;
width: 100%;
margin: 0;
overflow: hidden;
background-color: antiquewhite;
}
.text {
position: absolute;left: 5%;top: 50%;
font-size: 50px;color: white;line-height: 1.5;
text-shadow:0 10px 20px rgba(0, 0, 0, 0.4);
}
.objcover{width: 100%;height: 100%;object-fit: cover;}
.objcontain{width: 100%;height: 100%;object-fit: contain;}
div img{display: block;-webkit-user-drag: none;}
</style>
</head>
<body>
<div class="main">
<div class="wrap">
<dl>
<img src="images/tu1.jpg" class="objcover scrollpos" sc="-0.8">
<div class="text scrollpos" sc="0.7">图片1<br><span style="font-size: 22px">PC端浏览器请模拟触摸屏浏览<br><a href="http://www.flashme.cn" target="_blank">my web</a></span></div>
<div class="text scrollpos" sc="-0.5" style="left: 30%">跟着走</div>
</dl>
<dl>
<img src="images/tu2.jpg" class="objcontain">
<div class="text scrollpos" sc="0.7">图片2</div>
<div class="text scrollpos" sc="-0.5" style="left: 30%">跟着走啊</div>
</dl>
<dl>
<img src="images/tu1.jpg" class="objcover scrollscale" sc="-0.8">
<div class="text scrollpos" sc="0.5">图片3</div>
</dl>
<dl>
<img src="images/tu2.jpg" class="objcontain">
<div class="text scrollpos" sc="-0.9">图片4</div>
</dl>
<!-- 用户自己滚动,不需要补充高度了 -->
<!-- <div style="flex:0 0 100%;backdrop-filter: blur(2rem)"></div> -->
</div>
</div>
<script>
const main = document.querySelector('.main');
const wrap = document.querySelector('.wrap');
const dl = document.querySelectorAll('.wrap >dl');
const winH = main.clientHeight;
dl.forEach((ev, index)=>{
ev.querySelectorAll('.scrollpos, .scrollscale').forEach((ele, key)=>{
ele.dataset.index = index;
ele.dataset.top = ev.offsetTop;
ele.dataset.offtop = ele.offsetTop;
})
})
main.onscroll = function () {
scrollPosition(this.scrollTop);
}
function scrollPosition(_y) {
//滚动缩放
document.querySelectorAll('.scrollscale').forEach(function (ele) {
var rect = ele.getBoundingClientRect();
var scale = Math.abs(ele.dataset.top-_y)*0.001 + 1;
ele.style.transform='scale('+scale+','+scale+')';
})
//滚动位移
document.querySelectorAll('.scrollpos').forEach(function (ele) {
var sc=Number(ele.getAttribute('sc'));
ele.style.transform = "translateY(" + ((ele.dataset.top-_y)*sc) + "px)";
})
}
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/flashme/scrolldrag.git
git@gitee.com:flashme/scrolldrag.git
flashme
scrolldrag
scrolldrag
master

搜索帮助