首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将宽松纳入滚动绑定功能?

如何将宽松纳入滚动绑定功能?
EN

Stack Overflow用户
提问于 2018-10-18 11:40:28
回答 2查看 331关注 0票数 0

我在做一个垂直卷轴。在这个HTML上:

代码语言:javascript
复制
<div class="flex-container">
<div class="flex-caption">  
    <div>
        <p>.........</p>
        <h1>..........</h1>
    </div>
</div>
<div class="flex-caption">  
    <div>
        <p>.....</p>
    <h1>...........</h1>
    </div>
</div>
<div class="flex-caption">  
    <div>
        <p>.............</p>
        <h1>........../h1>
    </div>
</div>
</div>

我把CSS写成这样:

代码语言:javascript
复制
.caption-2 {
overflow: hidden;
position: fixed;
}


.flex-caption {
float: left;
}

.flex-container {
display: inline-flex;
width: 300vw;
transition-timing-function: cubic-bezier(.84,.01,.25,1.01);
transform: translateX(0vw);
}

然后用他的代码更改transform: translateX(0vw);

代码语言:javascript
复制
var captionCont, captionItem;

captionCont = document.querySelector(".flex-container");

window.onscroll = function() {scrollPost()};

function scrollPost () {

var y = window.scrollY;
var x = y / 20;
var i = x * 2;
animator(i);

}

function animator (y){
var captionCont;
captionCont = document.querySelector(".flex-container");
captionCont.style.transform = `translateX(${-y}vw)`
}

不过,我想试着在滚动这些元素时放松一下,这样感觉更像是动画而不是滚动。但是,我不想要一个触发动画,我希望动画从1%到100%被卷轴绑定。

我该怎么做?立方体bezier似乎做得不多。

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script
  src="https://code.jquery.com/jquery-3.3.1.js"
  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  crossorigin="anonymous"></script>
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
	<link href="animation-library.css" rel="stylesheet">
	<title>Wubbe Site</title>
</head>
<body>



<!-- Page no.2 -->

<div class="full-page" id="page-2">
	<video autoplay muted loop id="myVideo">
  <source src="fleuropdemo.mp4" type="video/mp4">
	</video>

<div class="caption-2">
	<div class="flex-container">
	<div class="flex-caption">	
		<div>
			<p>FLEUROP / BERZORGT EEN GOED GEVOEL</p>
			<h1> HET GEVOEL VAN BLOEMEN ANDERS VERTELD</h1>
		</div>
	</div>
	<div class="flex-caption">	
		<div>
			<p>FLEUROP</p>
		<h1>TITEL VAN PROJECT VRAAG EN OPLOSSING IN EEN MOOIE ZIN</h1>
		</div>
	</div>
	<div class="flex-caption">	
		<div>
			<p>FLEUROP / BERZORGT EEN GOED GEVOEL</p>
			<h1> HET GEVOEL VAN BLOEMEN ANDERS VERTELD</h1>
		</div>
	</div>
	</div>

	<div class="btn-container">
		<button>BEKIJK DE CASE</button>
		<button>AL ONZE CASES</button>
	</div>
	</div>
</div>

<div class="full-page">
	
</div>

<div class="full-page">
	
</div>
	

<style type="text/css">

.caption-2 {
	overflow: hidden;
	position: fixed;
}


.flex-caption {
	float: left;
}

.flex-container {
	display: inline-flex;
	width: 300vw;
	transition-timing-function: cubic-bezier(.84,.01,.25,1.01);
	transform: translateX(0vw);
}

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,600');

body {	
	background-size: 100%, 100%;
  	text-align: center;
  	max-width: none;
  	font-family: 'Open Sans', sans-serif;
  	color: black;
  	margin: 0;
  	background-color: black;
}

* {
	box-sizing: border-box;
}

.margin-left {
	margin-left: 6.25vw;
}

.margin-right {
	margin-right: 6.25vw;
}

.margin-top {
	top: 5vw;
}

.full-page {
	width: 100vw;
	height: 100vh;
}

button {
	width: 15%;
	background-color: white;
	height: 4rem;
	color: black;
	font-size: 18px;
	font-weight: bold;
}


#myVideo {
    position: fixed;
    right: 0;
    bottom: 0;
    min-width: 100%; 
    min-height: 100%;
}


#page-2 {
	background-image: url(page-2.png);
	background-size: 100%, 100%;
	background-repeat: no-repeat;
	background-attachment: fixed;
	background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    display: flex;
	justify-content: center;
	align-items: center;

}


.caption-2 {
	color: white;
	height: 70vh;
	width: 100vw;

    top: 10vw;
    z-index: 1;

}

.caption-2 p {
	font-size: 30px;
	font-weight: bolder;
}

.caption-2 h1 {
	font-size: 80px;
	margin-left: 15%;
	margin-right: 15%;
}

.caption-2 button {
	top: 16vh;
	position: relative;
}




</style>

<script type="text/javascript">

var captionCont, captionItem;

captionCont = document.querySelector(".flex-container");

window.onscroll = function() {scrollPost()};
	
function scrollPost () {
	
	var y = window.scrollY;
	var x = y / 20;
	var i = x * 2;
	animator(i);
	
	}

function animator (y){
	var captionCont;
	captionCont = document.querySelector(".flex-container");
	captionCont.style.transform = `translateX(${-y}vw)`
}
	


</script>


</body>
</html>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-18 12:08:47

我不明白你真正想要的是什么

代码语言:javascript
复制
var captionCont, captionItem;

captionCont = document.querySelector(".flex-container");

window.onscroll = function() {scrollPost()};
	
function scrollPost () {
	
	var y = window.scrollY;
	var x = y / 20;
	var i = x * 2;
	animator(i);
	
	}

function animator (y){
	var captionCont;
	captionCont = document.querySelector(".flex-container");
	captionCont.style.transform = `translateX(${-y}vw)`
}
代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script
  src="https://code.jquery.com/jquery-3.3.1.js"
  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  crossorigin="anonymous"></script>
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
	<link href="animation-library.css" rel="stylesheet">
	<title>Wubbe Site</title>
</head>
<body>



<!-- Page no.2 -->

<div class="full-page" id="page-2">
	<video autoplay muted loop id="myVideo">
  <source src="fleuropdemo.mp4" type="video/mp4">
	</video>

<div class="caption-2">
	<div class="flex-container">
	<div class="flex-caption">	
		<div>
			<p>FLEUROP / BERZORGT EEN GOED GEVOEL</p>
			<h1> HET GEVOEL VAN BLOEMEN ANDERS VERTELD</h1>
		</div>
	</div>
	<div class="flex-caption">	
		<div>
			<p>FLEUROP</p>
		<h1>TITEL VAN PROJECT VRAAG EN OPLOSSING IN EEN MOOIE ZIN</h1>
		</div>
	</div>
	<div class="flex-caption">	
		<div>
			<p>FLEUROP / BERZORGT EEN GOED GEVOEL</p>
			<h1> HET GEVOEL VAN BLOEMEN ANDERS VERTELD</h1>
		</div>
	</div>
	</div>

	<div class="btn-container">
		<button>BEKIJK DE CASE</button>
		<button>AL ONZE CASES</button>
	</div>
	</div>
</div>

<div class="full-page">
	
</div>

<div class="full-page">
	
</div>
	

<style type="text/css">

.caption-2 {
	overflow: hidden;
	position: fixed;
}


.flex-caption {
	float: left;
}

.flex-container {
	display: inline-flex;
	width: 300vw;
  transition: transform 0.3s linear;
	transform: translateX(0vw);
}

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,600');

body {	
	background-size: 100%, 100%;
  	text-align: center;
  	max-width: none;
  	font-family: 'Open Sans', sans-serif;
  	color: black;
  	margin: 0;
  	background-color: black;
}

* {
	box-sizing: border-box;
}

.margin-left {
	margin-left: 6.25vw;
}

.margin-right {
	margin-right: 6.25vw;
}

.margin-top {
	top: 5vw;
}

.full-page {
	width: 100vw;
	height: 100vh;
}

button {
	width: 15%;
	background-color: white;
	height: 4rem;
	color: black;
	font-size: 18px;
	font-weight: bold;
}


#myVideo {
    position: fixed;
    right: 0;
    bottom: 0;
    min-width: 100%; 
    min-height: 100%;
}


#page-2 {
	background-image: url(page-2.png);
	background-size: 100%, 100%;
	background-repeat: no-repeat;
	background-attachment: fixed;
	background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    display: flex;
	justify-content: center;
	align-items: center;

}


.caption-2 {
	color: white;
	height: 70vh;
	width: 100vw;

    top: 10vw;
    z-index: 1;

}

.caption-2 p {
	font-size: 30px;
	font-weight: bolder;
}

.caption-2 h1 {
	font-size: 80px;
	margin-left: 15%;
	margin-right: 15%;
}

.caption-2 button {
	top: 16vh;
	position: relative;
}




</style>




</body>
</html>

票数 1
EN

Stack Overflow用户

发布于 2018-10-18 11:57:18

包括jQuery.UI脚本,您的代码应该如下所示:

代码语言:javascript
复制
$('a').click(function(){
    var Top = 
$('body').find($(this).attr('href')).offset().top;
    $('html, body').animate({
        scrollTop: Top
    },300, 'easeOutExpo');

    return false;
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52873150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档