Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <div class="centerTitleGroup" id="titleGroup">
  2. </div>
  3.  
  4. // jQuery
  5. $(window).on("load", function() {
  6. if ( $(window).innerWidth() > 1000 ) {
  7. parallax("#titleGroup", 0.13);
  8. }
  9. });
  10.  
  11. // CSS
  12. .centerTitleGroup {
  13. backface-visibility: visible;
  14. }
  15.  
  16. // functions.php
  17. var parallax_items = [];
  18. function __parallax(element, top, multiplier) {
  19. var viewport = window.innerHeight;
  20. var height = $(element).outerHeight();
  21. var center = top + (height / 2);
  22. var offset = $(window).scrollTop();
  23. var calc = offset + (viewport / 2) - center;
  24. $(element).css("transform", "translateY(" + calc * multiplier * -1.0 + "px)");
  25. }
  26.  
  27. function parallax(element = null, multiplier = null) {
  28. if (element) {
  29. if (!$(element).length) {
  30. console.log("Failed to initialize parallax for element " + element);
  31. return;
  32. }
  33. if (!multiplier) {
  34. multiplier = .5;
  35. }
  36. parallax_items.push([element, $(element).offset().top, multiplier]);
  37. $(element).addClass("loaded").css('backface-visibility','hidden');
  38. parallax();
  39. }
  40. else {
  41. $(parallax_items).each(function() {
  42. __parallax(this[0], this[1], this[2]);
  43. });
  44. }
  45. }
  46.  
  47. $(window).scroll(function() {
  48. parallax();
  49. });
  50.  
  51. $(window).resize(function() {
  52. $(parallax_items).each(function(index) {
  53. element = this[0];
  54. var matrix = $(element).css("transform").replace(/[^0-9\-.,]/g, "").split(",");
  55. var transform = matrix[13] || matrix[5];
  56. parallax_items[index] = [this[0], $(this[0]).offset().top - transform, this[2]];
  57. });
  58. parallax();
  59. });
  60.  
  61. $(window).on("load", function() {
  62. parallax();
  63. });
  64. var parallax_img = document.querySelectorAll(".parallax .bg");
  65. for (var i = 0; i < parallax_img.length; i++) {
  66. parallax_img[i].innerHTML += '<div class="inner"></div>';
  67. }
  68.  
  69. $(".parallax .bg img").on("load", function() {
  70. var src = $(this).attr("src");
  71. var id = $(this).parent().parent().attr("id");
  72. $(this).siblings(".inner").css("background", "url(\"" + src + "\") no-repeat center center");
  73. $(this).siblings(".inner").addClass("loaded");
  74. $(this).siblings(".inner").attr("data-parent", id);
  75. $(this).remove();
  76. parallax(".parallax .bg .inner[data-parent=" + id + "]", -.1);
  77. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement