ftlabs / ftellipsis

Multi-line ellipsis made possible
MIT License
486 stars 39 forks source link

Line clamp doesn't go up when element gets taller #11

Closed mrdziuban closed 9 years ago

mrdziuban commented 9 years ago

I have an element with a height that is getting changed dynamically when the window is resized. When the window gets shorter, the element gets shorter and the line clamp on the child elements goes down properly. When the window gets taller, however, the element gets taller but the line clamp does not go up. Here's a jsfiddle example.

Is there a way I can fix this with my code?

matthew-andrews commented 9 years ago

Try this:- http://jsfiddle.net/rr6Lq86z/1/

(function() {
    var element = document.getElementById('ellipsis');
    element.style.height = (window.innerHeight/4)+'px';
    var ellipsis = new Ellipsis(element);
    ellipsis.calc();
    ellipsis.set();
    window.onresize = function() {
        ellipsis.unset();  // <- added this
        element.style.height = (window.innerHeight/4)+'px';
        ellipsis.calc();
        ellipsis.set();
    };
})();
matthew-andrews commented 9 years ago

[ Also, thanks for the really nice reduced test case—it's always really helpful when people provide this ]

mrdziuban commented 9 years ago

That worked perfectly, thank you! And thanks for the pure JS plugin, it's nice to find ones that don't depend on jQuery.

matthew-andrews commented 9 years ago

@mrdziuban http://matthew-andrews.github.io/talk-long-life-web-apps/#/52 :-)