Advertisement
rAthus

Dashed line from one element to another (images version)

Jul 20th, 2020
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.63 KB | None | 0 0
  1. <script>
  2.     jQuery(document).ready(function($) {
  3.         function genererPointilles($E1, $E2, $parent, zIndex) {
  4.             var borderWidth = 4;
  5.            
  6.             if (typeof($parent)=='undefined')
  7.                 var $parent = $('#ajax-content-wrap');
  8.             if (typeof(zIndex)=='undefined')
  9.                 var zIndex = 10;
  10.            
  11.             var topMargin = $parent.offset().top;
  12.             var leftMargin = $parent.offset().left;
  13.            
  14.             var Ax = $E1.offset().left+$E1.width()/2-leftMargin;
  15.             var Ay = $E1.offset().top+$E1.height()-topMargin;
  16.            
  17.             var Bx = $E2.offset().left+$E2.width()/2-leftMargin;
  18.             var By = $E2.offset().top-topMargin;
  19.            
  20.             if (Bx<Ax)
  21.                 var A2x = Math.round(Ax+(Bx-Ax)/2);
  22.             else
  23.                 var A2x = Math.round(Ax-borderWidth/2);
  24.             var A2y = Ay;
  25.             var A2w = Math.round(Math.abs((Ax-Bx)/2+borderWidth/2));
  26.             var A2h = Math.round(Math.abs((By-Ay)/2+borderWidth/2));
  27.            
  28.             if (Bx<Ax)
  29.                 var B2x = Math.round(Bx-borderWidth/2);
  30.             else
  31.                 var B2x = Math.round(Bx+(Ax-Bx)/2);
  32.             var B2y = Math.round(Ay+(By-Ay)/2-borderWidth/2);
  33.             var B2w = Math.round(A2w+borderWidth/2);
  34.             var B2h = Math.round(A2h+borderWidth/2);
  35.            
  36.             if (Math.abs(B2x-A2x)<10) {
  37.                 A2x = Math.round(A2x+(A2x-B2x)/2);
  38.                 B2x = A2x;
  39.             }
  40.            
  41.             if (B2x<A2x) {
  42.                 var class1 = 'bottomright';
  43.                 var class2 = 'topleft';
  44.             }
  45.             else if (B2x>A2x) {
  46.                 var class1 = 'bottomleft';
  47.                 var class2 = 'topright';
  48.             }
  49.             else {
  50.                 var class1 = 'straight-1';
  51.                 var class2 = 'straight-2';
  52.             }
  53.            
  54.             $parent.append('<div class="pointilles '+class1+'" style="left:'+A2x+'px;top:'+A2y+'px;width:'+A2w+'px;height:'+A2h+'px;z-index:'+zIndex+';"><div class="line line-1"></div><div class="line line-2"></div></div><div class="pointilles '+class2+'" style="left:'+B2x+'px;top:'+B2y+'px;width:'+B2w+'px;height:'+B2h+'px;z-index:'+zIndex+';"><div class="line line-1"></div><div class="line line-2"></div></div>');
  55.         }
  56.        
  57.         function pointilles() {
  58.             $('.pointilles').remove();
  59.             genererPointilles($('.pointilles-bloc-1 .column-bg-overlay-wrap'), $('.pointilles-bloc-2'));
  60.             genererPointilles($('.pointilles-bloc-2'), $('.pointilles-bloc-3'), $('.pointilles-wrapper-1'), 1);
  61.             genererPointilles($('.pointilles-bloc-3'), $('.pointilles-bloc-4'), $('.pointilles-wrapper-2'), 1);
  62.         }
  63.         pointilles();
  64.         $(window).resize(pointilles);
  65.     });
  66. </script>
  67. <style>
  68.     .pointilles {
  69.         position: absolute;
  70.         margin: 0;
  71.         padding: 0;
  72.         box-sizing: border-box;
  73.         overflow: hidden;
  74.     }
  75.     .pointilles.bottomright {
  76.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-corner-bottomright.png);
  77.         background-position: bottom right;
  78.         background-repeat: no-repeat;
  79.     }
  80.     .pointilles.bottomleft {
  81.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-corner-bottomleft.png);
  82.         background-position: bottom left;
  83.         background-repeat: no-repeat;
  84.     }
  85.     .pointilles.topright {
  86.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-corner-topright.png);
  87.         background-position: top right;
  88.         background-repeat: no-repeat;
  89.     }
  90.     .pointilles.topleft {
  91.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-corner-topleft.png);
  92.         background-position: top left;
  93.         background-repeat: no-repeat;
  94.     }
  95.     .pointilles.straight-1 {
  96.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-vertical.png);
  97.         background-position: bottom left;
  98.         background-repeat: repeat-y;
  99.         width: 4px !important;
  100.     }
  101.     .pointilles.straight-2 {
  102.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-vertical.png);
  103.         background-position: top left;
  104.         background-repeat: repeat-y;
  105.         width: 4px !important;
  106.     }
  107.     .pointilles.none {
  108.         display: none;
  109.     }
  110.     .pointilles .line {
  111.         position: absolute;
  112.         margin: 0;
  113.         padding: 0;
  114.         box-sizing: border-box;
  115.         width: 100%;
  116.         height: 100%;
  117.     }
  118.     .pointilles.straight-1 .line, .pointilles.straight-2 .line {
  119.         display: none;
  120.     }
  121.     .pointilles.bottomright .line-1 {
  122.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-horizontal.png);
  123.         background-position: bottom right;
  124.         background-repeat: repeat-x;
  125.         margin-left: -52px;
  126.     }
  127.     .pointilles.bottomright .line-2 {
  128.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-vertical.png);
  129.         background-position: bottom right;
  130.         background-repeat: repeat-y;
  131.         margin-top: -75px;
  132.     }
  133.     .pointilles.bottomleft .line-1 {
  134.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-horizontal.png);
  135.         background-position: bottom left;
  136.         background-repeat: repeat-x;
  137.         margin-left: 65px;
  138.     }
  139.     .pointilles.bottomleft .line-2 {
  140.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-vertical.png);
  141.         background-position: bottom left;
  142.         background-repeat: repeat-y;
  143.         margin-top: -75px;
  144.     }
  145.     .pointilles.topright .line-1 {
  146.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-horizontal.png);
  147.         background-position: top right;
  148.         background-repeat: repeat-x;
  149.         margin-left: -52px;
  150.     }
  151.     .pointilles.topright .line-2 {
  152.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-vertical.png);
  153.         background-position: top right;
  154.         background-repeat: repeat-y;
  155.         margin-top: 65px;
  156.     }
  157.     .pointilles.topleft .line-1 {
  158.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-horizontal.png);
  159.         background-position: top left;
  160.         background-repeat: repeat-x;
  161.         margin-left: 65px;
  162.     }
  163.     .pointilles.topleft .line-2 {
  164.         background-image: url(/wp-content/themes/salient-child/img/trace-dash-straight-vertical.png);
  165.         background-position: top left;
  166.         background-repeat: repeat-y;
  167.         margin-top: 65px;
  168.     }
  169. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement