A
A
Anton2018-08-28 14:05:37
css
Anton, 2018-08-28 14:05:37

Canvas doesn't work if parent has display none?

I made a switch to show / hide the contents of the div main in js

document.getElementById('main').style.display = 'block';

<div class="main" style="display:none">
<div class="col-sm-8">
            <div class="view-wrapper">
                <div id="container">
                    <canvas id="image"></canvas>
                </div>
            </div>
 </div>
<!-- еще какие то коды -->
 </div>

The problem is that when the block changes display from none to block , the canvas is empty
. In other words, the canvas does not draw an image when display:none.
How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
stainer, 2018-08-28
@stainer

js - looks for id
in html given class

K
Koreetz Koreetz, 2018-08-28
@shnopik87

document.querySelector('.main').style.display = 'block';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question