1

私はOOPに非常に慣れていません。私の理解では、それはCSSクラスのようなもので、クラスがあり、それを適用/使用できます。

これは私のコードです。

$(".mybutton").click(function(){
    $(this).siblings('.mybutton').removeClass('active').end().addClass('active');           
});


$('.mybutton, .second').click(function(event){
    $('#thisDiv').hide().filter(this.hash).show();
    event.preventDefault();
});

$('.second').on("click", function(){
$(".mybutton").eq(1).siblings('.mybutton').removeClass('active').end().addClass('active');
    $("html, body").animate({
        scrollTop: $('#contact').offset().left - 20},
        800);
});

それらをoopスタイルに変換するにはどうすればよいですか?

var Doit = {
    init:function(){
        $(".mybutton").on("click", this.active);
    },
    active:function(){
    $(this)
      .siblings('.mybutton')
          .removeClass('active')
              .end().addClass('active');
    },
    filter:function {


    }


};

Doit.init();

私のコードを本当に OOP に変更する必要がある場合、誰かが私にヒントを与えることができれば?

ありがとう

4

1 に答える 1