Jangga
Junior Member
- Aug 8, 2016
- 196
- 11
Please guys. I'm working on making an animation on an element as soon as the user sroll his browser window downwards but I've tried countless times and it refuse to work . I'm giving up already pls help me....pls help watever way u can
Html page structure
My css here
My Js Here
Html page structure
Code:
<! Document>
<html>
<head>
<Script type="text/javascript" src="styles/js/jquery-1.11.1.min.js">
<Script type="text/javascript" src="styles/js/script.js">
<Script>
//on or scroll, detect elements in view
$window.on('scroll resize', check_if_in_view);
//trigger our scroll event on initial load $window.trigger('scroll');
</script>
</head>
<body>
<div class="container-fluid">
<div class="well col-sm-6 col-xs-12">
<div class="animation-element slide-left">
MY TEXT GOES HERE
</div></div></div>
My css here
Code:
/*animation element*/
.animation-element {
opacity: 0;
position: relative;
}
/*animation element sliding left*/
.animation-element.slide-left {
opacity: 0;
-moz-transition: all 500ms linear;
-webkit-transition: all 500ms linear;
-o-transition: all 500ms linear;
transition: all 500ms linear;
-moz-transform: translate3d(-100px, 0px, 0px);
-webkit-transform: translate3d(-100px, 0px, 0px);
-o-transform: translate(-100px, 0px);
-ms-transform: translate(-100px, 0px);
transform: translate3d(-100px, 0px, 0px);
}
.animation-element.slide-left.in-view {
opacity: 1;
-moz-transform: translate3d(0px, 0px, 0px);
-webkit-transform: translate3d(0px, 0px, 0px);
-o-transform: translate(0px, 0px);
-ms-transform: translate(0px, 0px);
transform: translate3d(0px, 0px, 0px);
}
My Js Here
Code:
var $animation_elements = $('.animation-element');
var $window = $(window);
function check_if_in_view() {
var window_height = $window.height();
var window_top_position = $window.scrollTop();
var window_bottom_position = (window_top_position + window_height);
$.each($animation_elements, function() {
var $element = $(this);
var element_height = $element.outerHeight();
var element_top_position = $element.offset().top;
var element_bottom_position = (element_top_position + element_height);
//check to see if this current container is within viewport
if ((element_bottom_position >= window_top_position) &&
(element_top_position <= window_bottom_position)) {
$element.removeClass('in-view');
} else {
$element.addClass('in-view');
}
});
}