1

オリジナルをhtml/cssで作成した別のプラグイン、つまりセレクトボックスに置き換えるプラグインを書いています。

パフォーマンスに問題があり、コードがかなり重いことを認識しています。最初に、各選択の ID を取得し、HTML コードの後に​​幅、位置などのいくつかの css パラメーターを追加します...

$(this).after("<div class="selectbox" s-id='"+$(this).attr("id")+"'> the code of the select </div>");

次に、選択を非表示にすると、かなり重いと思われる部分が来ます。これのすべてのオプションを使用して、これを行います

var selectbox=$("div[s-id="+selectID+"]"); //This is the div previously added after.

//each option of the select will be converted into a div
$.each($(this).find("option"), function(i) {
    var valor = $(this).val(),
        texto = $(this).text();

    if (i == 0) 
        selectbox.find(".class_valor").text(texto);//The first option to be shown

    //Then I add a li to my drop
    selectbox.find("ul").append('<li  data-value="'+valor+'">'+texto+'</li>');
});

さて、これがドロップダウンとオプションへのクリックを開くトリガーにイベントを追加する最良の方法であるかどうかはわかりません。これはselectbox関数の内部ではなく、内部の外部にあります(function($){

コードは次のとおりです。 http://codepen.io/anon/pen/kcpxl

4

1 に答える 1