平滑滚动,每个内容以不同的速度滚动
Smooth scroll where each content scrolled with different speed
我想做一个像这个页面一样平滑的滚动。我可以看到它就像一个视差滚动,但背景跟随内容延迟。有什么办法可以做到这一点吗?我尝试了很多库,如Stellar.js等,但我只能实现"正常"视差效果,背景滚动比内容慢/快。
这将帮助你,我们可以控制车轮速度和距离
if (window.addEventListener) window.addEventListener('DOMMouseScroll', scroll, false);
window.onmousewheel = document.onmousewheel = scroll;
function scroll(event) {
var delta = 0;
if (event.scrollDelta) delta = event.scrollDelta / 100;
else if (event.detail) delta = -event.detail / 3;
handleScroll(delta);
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}
function handleScroll(delta) {
var time = 1000;
var distance = 200;
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - (distance * delta)
}, time );
}
#myDiv {
height:2000px;
width:100%;
background-color:red;
padding: 5px;
margin: 5px;
overflow:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br/>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
相关文章:
- 如何计算另一个元素上滚动速度的乘数,使它们同时到达终点(视图顶部)
- 用于获得“;两个不同的滚动速度“;在这个网站上?(请参阅内部链接)
- Jquery JScrollPane-设置滚动速度/灵敏度
- 整页.js从一个部分跳到另一个部分时如何控制滚动速度
- 使用鼠标滚轮jquery插件的滚动速度
- 滚动时加载更多 滚动速度时一次工作两次
- 淡入和淡出闪烁,如果滚动速度很快
- 如何向脚本窗口添加滚动速度
- 当您使用 Jquery 按下按钮时,我正在尝试使我的页面滚动速度变慢
- CSS 在滚动时会发生变化,但会随着滚动速度而变化
- 整页更改特定部分的滚动速度
- 增加滚动速度的功能
- 可以't修改滚动速度
- Javascript函数可以降低滚动速度
- 如何提高Monocle电子阅读器库的滚动速度
- 使用JavaScript计算鼠标滚轮滚动速度
- jQuery.ScrollTo -如何使bg滚动速度比其他慢
- 改变jscrollpane的滚动速度
- 将body的简单滚动速度更改为特定类
- 滚动速度操作css jquery