CSS transitions not effecting HTML generated by Javascript -
i have css transform rotates objects on hover.
.rotate { transition: 0.2s; } .rotate:hover { transform: rotate(20deg); }
this works fine when applied hard coded html element.
however page contains script generates more html , inserts div (div.innerhtml = newhtml).
the css transitions not work on elements generated script.
why case , how can corrected?
edit: here simplified example shows code, i'm unable example work @ all, hard coded rotate , generated html don't rotate , have no idea why.
<!doctype html> <head> <style> .rotate { transition: 0.2s; } .rotate:hover { transform: rotate(20deg); } </style> </head> <body> <a class="rotate" href="#">a test text</a> <div id="plot"></div> <script> function makehtml() { return '<a class="rotate" href="#">i html link</a>'; } var plot = document.getelementbyid('plot'); var text = makehtml(); plot.innerhtml = text; </script> </body> </html>
transform
applies block-level elements. default, <a>
elements have display:inline
. need apply display: inline-block;
, transform
work:
function makehtml() { return '<a class="rotate" href="#">i html link</a>'; } var plot = document.getelementbyid('plot'), text = makehtml(); plot.innerhtml = text;
.rotate { transition: 0.2s; display: inline-block; } .rotate:hover { transform: rotate(20deg); }
<a class="rotate" href="#">a test text</a> <div id="plot"></div>
Comments
Post a Comment