/    Sign up×
Community /Pin to ProfileBookmark

Animation elements that slide into view on Scroll

I found this code in a magazine, from my understanding, it’s supposed to slide a full image into view on scroll, overlapping the previous image like this:[url]http://fitness.reebok.co.uk/be-more-human/#/home[/url]

The code is as follows:
CSS:

[CODE]
.inView{
opacity:1;
-webkit-transform:translateY(0); -ms-transform: translateY(0); transform:translateY(0); -webkit-animation:none;
}
.slideIn{
opacity:0;
-webkit-transform:
translateY(200px);
-ms-transform: translateY(200px);
transform:translateY(200px);
-webkit-animation-name:slideIn;
animation-name:slideIn;

-webkit-animation-duration:1.5s;
animation-duration:1.5s;
-webkit-animation-fill-mode:forwards;
animation-fill-mode:forwards;
}
/*.inView class here or below next class!*/
@keyframes slideIn{
to{
opacity:1;
-webkit-transform:translateY(0); -ms-transform: translateY(0); transform:translateY(0);
}
}

[/CODE]

Javascript:

[CODE]<script src=”http://code.jquery.com/jquery-1.11.2.min.js”></script>
<script src=”jquery.visible.js”></script>

<script>
//returns true if whole element is visible:
$(‘#element’).visible();
//Returns true if only part of element is visible
$(‘#element’).visible(true);

$(‘#element:visible’).visible();

$(‘#element:visible’).visible(false,true);
</script>

<script>
$(“.content”).each(function(index,elment){
if ($(element).visible(true,’vertical’)){
$(element).addClass(“inView”);
}
});
</script>
<script>
var prevScrollTop =0;
$(window).scroll(function(event){
var scrollTop=$(this).scrollTop();
if (scrollTop > prevScrollTop){
$(“.content”).each(function(index,element){

if ($(element).visible(true,’vertical’)){
$(element).addClass(“slideIn”);
}
});
prevScrollTop=scrollTop;
}
});
</script>
[/CODE]

My code:

[CODE]<html>
<head>
<style>

.inView{
opacity:1;
-webkit-transform:translateY(0); -ms-transform: translateY(0); transform:translateY(0); -webkit-animation:none;
}
.slideIn{
opacity:0;
-webkit-transform:
translateY(200px);
-ms-transform: translateY(200px);
transform:translateY(200px);
-webkit-animation-name:slideIn;
animation-name:slideIn;

-webkit-animation-duration:1.5s;
animation-duration:1.5s;
-webkit-animation-fill-mode:forwards;
animation-fill-mode:forwards;
}
/*.inView class here or below next class!*/
@keyframes slideIn{
to{
opacity:1;
-webkit-transform:translateY(0); -ms-transform: translateY(0); transform:translateY(0);
}
}

</style>
<title>I like cheese</title>

</head>
<body>

<div class=”container”>
<img src=”BG.jpg”></img>
</div>
<div class=”img2″>
<img src=”ChristmasTree1.jpg”></img>
</div>
<script src=”http://code.jquery.com/jquery-1.11.2.min.js”></script>
<script src=”jquery.visible.js”></script>

<script>
//returns true if whole element is visible:
$(‘#element’).visible();
//Returns true if only part of element is visible
$(‘#element’).visible(true);

$(‘#element:visible’).visible();

$(‘#element:visible’).visible(false,true);
</script>

<script>
$(“.content”).each(function(index,elment){
if ($(element).visible(true,’vertical’)){
$(element).addClass(“inView”);
}
});
</script>
<script>
var prevScrollTop =0;
$(window).scroll(function(event){
var scrollTop=$(this).scrollTop();
if (scrollTop > prevScrollTop){
$(“.content”).each(function(index,element){

if ($(element).visible(true,’vertical’)){
$(element).addClass(“slideIn”);
}
});
prevScrollTop=scrollTop;
}
});

</script>
</body>
</html>[/CODE]

I’m new to javascript, I don’t know what I’m supposed to do to get this to work. Extremely grateful for anyone that can help me out.

to post a comment
HTML

0Be the first to comment 😎

×

Success!

Help @jzhang172 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...