html - Javascript smoothscroll isn't working -
still working on site: http://i333180.iris.fhict.nl/p2_vc/
there button navigate down te page, action instant smooth scrolling nicer.
so, google around, tried lot , shortest script found on: cant working.
$(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; } } }); });
ref: https://css-tricks.com/snippets/jquery/smooth-scrolling/
this how added code between
<head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(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; } } }); }); </script> </head>
button:
<body> <a id='button_down' href='#section' onclick="document.getelementbyid('moodvideo').pause()"><img src='scroll.png' alt='scroll'></a> </body>
i inspected example site witch given , added on same way html. ref inspected link: https://css-tricks.com/examples/smoothpagescroll/ cant make working..
also, have other script, witch needs same action, after end of video. script now:
<script> function videoended() { window.location.href="#section"; } </script>
this has same thing; scroll nicely.
i hoped explained understandable, if not, i'd try again. regards
edit script isnt added online site because script isnt working yet, if make easer add online.
update site online not working scripts
the script works on links on live copy intended, believe mean videoend()
function.
the smooth scrolling script found works anchor tags (<a>
).
as window.location.href = "#section"
not anchor tag, not affected script.
what can take important bits of script , use in videoend()
function so.
function videoended() { $('html,body').animate({ scrolltop: $("#section").offset().top }, 1000); }
edit:
the reason not working because you're browsing page using file://
protocol , script source links jquery
//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
which uses //
relative scheme, means browser append current browsing scheme, turning this..
file://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
which not exist. if specify http://
work
http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
Comments
Post a Comment