Guest User

Untitled

a guest
Nov 22nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. $('.js-svg-animation').each(function () {
  2. var $svg = $(this);
  3. var $paths = $svg.find('path');
  4.  
  5. $paths.each(function (i, path) {
  6. function takePathStartPosition() {
  7. var total_length = path.getTotalLength();
  8.  
  9. total_length = /Firefox/i.test(navigator.userAgent) ? total_length + 22 : total_length; // firefox bug
  10.  
  11. $(path).attr('stroke-dasharray', total_length + ' ' + total_length);
  12. $(path).attr('stroke-dashoffset', total_length);
  13. }
  14.  
  15. takePathStartPosition(); // задаём начальное положение svg (не зарисованное)
  16.  
  17. $(window).on('scroll', function () {
  18. if (!$svg.hasClass('is-ready') && $(window).scrollTop() + window.innerHeight > $svg.offset().top + 100) {
  19. $svg.addClass('svg-animation-path is-ready');
  20. $(path).attr('stroke-dashoffset', 0);
  21. }
  22. });
  23. });
  24. });
Add Comment
Please, Sign In to add comment