Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function redraw_scripts(scripts) {
  2. // 원본 대비 줄어든 비율을 적용함
  3. first_img_el = document.querySelector('div.content_area > img');
  4. first_img_el_rect = first_img_el.getBoundingClientRect();
  5. ratio = first_img_el.width / first_img_el.naturalWidth * 100;
  6.  
  7. content_area_el = document.querySelector('div.content_area');
  8. content_area_el_rect = content_area_el.getBoundingClientRect();
  9.  
  10. margin_top = window.pageYOffset + first_img_el_rect.y;
  11. margin_left = first_img_el_rect.x - content_area_el_rect.x;
  12.  
  13. elements = document.querySelectorAll('.episode__script');
  14. elements.forEach(function(el) {
  15. el.remove();
  16. });
  17.  
  18. scripts.forEach(function(script) {
  19. var left = (script['x'] * ratio / 100) + margin_left;
  20. var top = (script['y'] * ratio / 100) + margin_top;
  21. var width = (script['width'] * ratio / 100);
  22. var font_size = (script['height'] * ratio / 100) - 6;
  23. var tag = '<div class="episode__script" style="z-index:10;position:absolute;left:'+left+'px; top:'+top+'px; min-width:'+width+'px; font-size:'+font_size+'px;">'+script['text']+'</div>';
  24. var new_el = document.createElement('div');
  25. new_el.innerHTML = tag;
  26. content_area_el.prepend(new_el.firstChild);
  27. });
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement