jquery - Javascript smoothscrolling still lagging -
i'm working on page: http://i333180.iris.fhict.nl/p2_vc/
after some of here, have added smooth scroll plugin.
however, noticed lot of scroll lag when page first opened.
what i've tried
- i compressed background image 10 mb 2.2mb (1280 x 1024).
i moved background image div element, on content , not behind video.
<div id="div_section_img"> <!-- content --> </div>#div_section_img{ background: url("nature.png") no-repeat center center fixed; }- in doing so, strange 'blank' line appeared between video , content section. think because video height set
100vh.
i managed fix issue changing
margin-topsettingpadding-topon#logo,footerelement.#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); }- in doing so, strange 'blank' line appeared between video , content section. think because video height set
while of has helped somewhat, there still noticeable amount of scroll lag.
how can rid of 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; } } }); }); - even scroll top 5000 lagging
update tried script instead of 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 still noticeable
you need hide page while loading user doesn't start scrolling until has loaded.
- add class the
htmltag hides body tag , adds loading image background ofhtmltag - wait load
- remove added class, restoring page natural state.
var 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; } <!-- demo purposes --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <img src="//lorempixel.com/1024/768">
Comments
Post a Comment