main.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. $(window).scroll(function() {
  2. if ($(document).scrollTop() > 80) {
  3. $('nav').addClass('shrink');
  4. } else {
  5. $('nav').removeClass('shrink');
  6. }
  7. });
  8. $(function(){
  9. jQuery('img.svg').each(function(){
  10. var $img = jQuery(this);
  11. var imgID = $img.attr('id');
  12. var imgClass = $img.attr('class');
  13. var imgURL = $img.attr('src');
  14. jQuery.get(imgURL, function(data) {
  15. // Get the SVG tag, ignore the rest
  16. var $svg = jQuery(data).find('svg');
  17. // Add replaced image's ID to the new SVG
  18. if(typeof imgID !== 'undefined') {
  19. $svg = $svg.attr('id', imgID);
  20. }
  21. // Add replaced image's classes to the new SVG
  22. if(typeof imgClass !== 'undefined') {
  23. $svg = $svg.attr('class', imgClass+' replaced-svg');
  24. }
  25. // Remove any invalid XML tags as per http://validator.w3.org
  26. $svg = $svg.removeAttr('xmlns:a');
  27. // Check if the viewport is set, else we gonna set it if we can.
  28. if(!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {
  29. $svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))
  30. }
  31. // Replace image with new SVG
  32. $img.replaceWith($svg);
  33. }, 'xml');
  34. });
  35. });