Skip to content

Image size issue in epub.js 3

Stanislav edited this page Apr 28, 2019 · 2 revisions

In version 2 of epub.js I solve images size issue by using smartimages hook. now how can I solve this size problem in current version of epub.js.

Answer:

You can try to use next code, if I understand you correctly:

rendition.hooks.content.register(function (contents, view) {
        var css = 'img { max-width: 100%; height: auto;}';
        var head = contents.document.getElementsByTagName('head')[0];
        var s = contents.document.createElement('style');
        s.setAttribute('type', 'text/css');
        if (s.styleSheet) {   // IE
            s.styleSheet.cssText = css;
        } else {                // the world
            s.appendChild(contents.document.createTextNode(css));
        }
        head.appendChild(s);
})