How to toggle content in Semantic UI buttons?

前端 未结 4 1341
春和景丽
春和景丽 2021-02-05 06:00

The documentation says a button can be formatted to toggle on or off, but the example given is merely

Vote &
4条回答
  •  春和景丽
    2021-02-05 06:24

    The below code is doing the magic:

    semantic.button = {};
    
    // ready event
    semantic.button.ready = function() {
    
      // selector cache
      var
        $buttons = $('.ui.buttons .button'),
        $toggle  = $('.main .ui.toggle.button'),
        $button  = $('.ui.button').not($buttons).not($toggle),
        // alias
        handler = {
    
          activate: function() {
            $(this)
              .addClass('active')
              .siblings()
              .removeClass('active')
            ;
          }
    
        }
      ;
    
      $buttons
        .on('click', handler.activate)
      ;
    
    
      $toggle
        .state({
          text: {
            inactive : 'Vote',
            active   : 'Voted'
          }
        })
      ;
    
    };
    
    
    // attach ready event
    $(document)
      .ready(semantic.button.ready)
    ;
    

提交回复
热议问题