Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function redraw_scripts(scripts) {
- // 원본 대비 줄어든 비율을 적용함
- first_img_el = document.querySelector('div.content_area > img');
- first_img_el_rect = first_img_el.getBoundingClientRect();
- ratio = first_img_el.width / first_img_el.naturalWidth * 100;
- content_area_el = document.querySelector('div.content_area');
- content_area_el_rect = content_area_el.getBoundingClientRect();
- margin_top = window.pageYOffset + first_img_el_rect.y;
- margin_left = first_img_el_rect.x - content_area_el_rect.x;
- elements = document.querySelectorAll('.episode__script');
- elements.forEach(function(el) {
- el.remove();
- });
- scripts.forEach(function(script) {
- var left = (script['x'] * ratio / 100) + margin_left;
- var top = (script['y'] * ratio / 100) + margin_top;
- var width = (script['width'] * ratio / 100);
- var font_size = (script['height'] * ratio / 100) - 6;
- 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>';
- var new_el = document.createElement('div');
- new_el.innerHTML = tag;
- content_area_el.prepend(new_el.firstChild);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement