main.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. $(document).ready(function(){
  2. var _$users = $('div.user');
  3. function init(){
  4. wrapHTML();
  5. getOutImages();
  6. randomPosition($('div.user h1:first'));
  7. randomPosition($('div.user h2:first'));
  8. createLineHeader();
  9. createLineContent();
  10. createLineContentImages();
  11. createLineImages();
  12. }
  13. function wrapHTML(){
  14. _$users.each(function(){
  15. var $header = $('<header />').append($('h1:first, h2:first', this));
  16. $header.prependTo(this)
  17. });
  18. }
  19. function getOutImages(){
  20. $('div.user img').each(function(){
  21. var cnt = $(this).parent('p').contents();
  22. $(this).parent('p').replaceWith(cnt);
  23. });
  24. }
  25. function createLineHeader(){
  26. _$users.each(function(){
  27. var h2Height = $(this).find('h2:first').outerHeight();
  28. var h1Width = $(this).find('h1:first').outerWidth();
  29. var x1 = $(this).find('h2:first').position().left + 50;
  30. var y1 = $(this).find('h2:first').position().top + h2Height;
  31. var x2 = $(this).find('h1:first').position().left + (h1Width / 2);
  32. var y2 = $(this).find('h1:first').position().top;
  33. // console.log(x1, x2, y1, y2);
  34. var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
  35. });
  36. }
  37. function createLineContent(){
  38. _$users.each(function(){
  39. var h1Height = $(this).find('h1:first').outerHeight();
  40. // var h1Width = $(this).find('h1').outerWidth();
  41. var x1 = $(this).find('h1:first').position().left + 50;
  42. var y1 = $(this).find('h1:first').position().top + h1Height;
  43. var x2 = $(this).find('.content').position().left;
  44. var y2 = $(this).find('.content').position().top;
  45. // console.log(x1, x2, y1, y2);
  46. var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
  47. });
  48. }
  49. function createLineContentImages(){
  50. _$users.each(function(){
  51. var contentHeight = $(this).find('.content').outerHeight();
  52. // var h1Width = $(this).find('h1').outerWidth();
  53. var x1 = $(this).find('.content').position().left;
  54. var y1 = $(this).find('.content').position().top + contentHeight;
  55. var x2 = $(this).find('.images').position().left + 100;
  56. var y2 = $(this).find('.images').position().top + 10;
  57. // console.log(x1, x2, y1, y2);
  58. if($(this).find('.images').find('li').length){
  59. var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
  60. }
  61. });
  62. }
  63. function createLineImages(){
  64. _$users.each(function(){
  65. $(this).find('.images').find('li').each(function(){
  66. var height = $(this).outerHeight();
  67. var width = $(this).outerWidth();
  68. if($(this).next().length){
  69. // console.log($(this));
  70. var x1 = $(this).position().left + width ;
  71. var y1 = $(this).position().top + height + 15;
  72. var x2 = $(this).next().position().left + width - 100;
  73. var y2 = $(this).next().position().top + 16;
  74. var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
  75. // console.log(y1);
  76. }
  77. });
  78. });
  79. }
  80. function randomPosition($element){
  81. $element.each(function(){
  82. var randomPos = Math.random() * (_$users.width()- $(this).width());
  83. var width = $(this).width();
  84. $(this).css({
  85. 'left': randomPos,
  86. 'width': width
  87. });
  88. });
  89. }
  90. init();
  91. });