Chosen harvesthq resize width dynamically

前端 未结 12 1600
渐次进展
渐次进展 2020-12-30 03:49

How can you have a harvesthq Chosen dropdown with a dynamic width style?

By default it has a fixed width and if you try to modify it with CSS you will have several p

12条回答
  •  感情败类
    2020-12-30 04:04

    For me, what it really worked was this:

    function resizeChosen() {
        var chosen = $("#dropdown_chosen");
        var max = chosen.parent().width();
        var currentWidth = chosen.width();
        var now = currentWidth + 20 / 100 * currentWidth;
    
        if (now <= max) {
            $("#dropdown_chosen").attr('style', "width: " + now + "px");
        }
    }
    

    and inside document.ready

    dropdown.chosen().change(function() {
        resizeChosen();
    });
    

    where dropdown is id of the dropdown. You can also set width decrease on change event. #dropdown_chosen is created by chosen as follows:

    dropdown - your dropdown id append _chosen

提交回复
热议问题