Advertisement
bongzilla

Untitled

Aug 26th, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. $(document).ready(function(e) {
  2. // изменения clip-path блоков при наведении на соответственно:
  3. // changesMatrix[0] - 1 и 4 блок; changesMatrix[1] - 3 и 6 блок; changesMatrix[2] - 2 и 5 блок
  4. let changesMatrix = [
  5. [
  6. "polygon(0 0, 95% 0, 100% 100%, 0 100%)",
  7. "polygon(0 0, 95% 0, 100% 100%, 0 100%)",
  8. "polygon(0 0, 100% 0, 100% 100%, 5% 100%)",
  9. "polygon(0 0, 100% 0, 95% 100%, 0 100%)",
  10. "polygon(5% 0, 100% 0, 95% 100%, 0% 100%)",
  11. "polygon(5% 0, 100% 0, 100% 100%, 0 100%)"
  12. ],
  13. [
  14. "polygon(0 0, 100% 0, 95% 100%, 0 100%)",
  15. "polygon(5% 0, 100% 0, 95% 100%, 0 100%)",
  16. "polygon(5% 0, 100% 0, 100% 100%, 0 100%)",
  17. "polygon(0 0, 95% 0, 100% 100%, 0 100%)",
  18. "polygon(0 0, 95% 0, 100% 100%, 5% 100%)",
  19. "polygon(0 0, 100% 0, 100% 100%, 5% 100%)",
  20. ],
  21. [
  22. "polygon(0 0, 100% 0, 95% 100%, 0 100%)",
  23. "polygon(5% 0, 95% 0, 100% 100%, 0 100%)",
  24. "polygon(0 0, 100% 0, 100% 100%, 5% 100%)",
  25. "polygon(0 0, 95% 0, 100% 100%, 0 100%)",
  26. "polygon(0 0, 100% 0, 95% 100%, 5% 100%)",
  27. "polygon(5% 0, 100% 0, 100% 100%, 0 100%)",
  28. ]
  29. ];
  30.  
  31. function applyClipPaths($blocks, arrayOfBlockIndexes, arrayOfChanges) {
  32. $.each(arrayOfBlockIndexes, function(idx, value) {
  33. $blocks.eq(value).on("mouseover", function(e) {
  34. $blocks.each(function(blockIdx) {
  35. $(this).css({
  36. "clip-path": arrayOfChanges[blockIdx]
  37. })
  38. })
  39. })
  40. })
  41. }
  42.  
  43. if(window.innerWidth > 1024) {
  44. let $blocks = $(".block");
  45.  
  46. applyClipPaths($blocks, [0, 3], changesMatrix[0]);
  47. applyClipPaths($blocks, [2, 5], changesMatrix[1]);
  48. applyClipPaths($blocks, [1, 4], changesMatrix[2]);
  49.  
  50. // возврат в нормальное состояние после убирания hover'а
  51. $blocks.on("mouseleave", function(e) {
  52. $blocks.each(function(idx) {
  53. $(this).css({
  54. "clip-path": "polygon(0 0, 100% 0, 100% 100%, 0 100%)"
  55. })
  56. })
  57. })
  58. }
  59.  
  60. });
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement