Reputation: 1078
I'm working on this page: http://i333180.iris.fhict.nl/p2_vc/
After some help from some of you here, I have successfully added a smooth scroll plugin.
However, I am noticed a lot of scroll lag when the page is first opened.
What I've Tried
I moved the background image to a div element, so it was only on the content and not behind the video.
<div id="div_section_img">
<!-- all content -->
</div>
#div_section_img{
background: url("nature.png") no-repeat center center fixed;
}
100vh
.I managed to fix this issue by changing the margin-top
setting to padding-top
on #logo
and the footer
element.
#logo {
width: 410px;
**padding-top: 120px;**
margin-left: auto;
margin-right: auto;
margin-bottom: 0px;
}
footer {
**padding-top: 100px;**
width: 100%;
height: 300px;
background-color: rgba(25, 25, 25, 0.8);
}
While all of this has helped somewhat, there is still a very noticeable amount of scroll lag.
How can I get rid of the scroll lag?
smooth-scroll.js
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
Update Tried this script instead of the other scripts
function start(){
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
function videoEnded() {
$('html,body').animate({
scrollTop: $("#section").offset().top
}, 1000);
}
}
window.onload = start;
But still lagging
Update 2 Added
var loading = $('html');
loading.addClass('loading');
$(window).load(function(){
loading.removeClass('loading');
});
Code works, lag is still noticeable
Upvotes: 5
Views: 1405
Reputation:
You need to hide the page while it is loading so the user doesn't start scrolling until everything has loaded.
html
tag which hides body tag and adds a loading image to the background of the html
tagvar loading = $('html');
loading.addClass('loading');
$(window).load(function(){
loading.removeClass('loading');
});
html.loading {
height: 100%;
background-image: url('http://i.imgur.com/HEAhF9v.gif'); /* Animated loading spinner image */
background-position: center center;
background-repeat: no-repeat
}
html.loading body {
visibility: hidden;
height: 100%;
overflow: hidden;
}
<!-- For demo purposes only -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img src="//lorempixel.com/1024/768">
Upvotes: 1