Tooltip on click of a button

后端 未结 7 949
执笔经年
执笔经年 2021-01-01 20:31

I\'m using clipboard.js to copy some text from a textarea, and that\'s working fine, but I want to show a tooltip saying \"Copied!\" if it was successfully copi

7条回答
  •  执笔经年
    2021-01-01 21:04

    This solution work, if you have some buttons and etc:

    function setTooltip(e,message) {
      $(e.trigger).tooltip({
      trigger: 'click',
      placement: 'bottom'
    });
    $(e.trigger).tooltip('hide')
     .attr('data-original-title', message)
     .tooltip('show');
    }
    
    function hideTooltip(e) {
      setTimeout(function() {
        $(e.trigger).tooltip('hide');
      }, 1000);
    }
    
    // Clipboard
    
    var clipboard = new Clipboard('button');
    
    clipboard.on('success', function(e) {
      setTooltip(e,'Copied!');
      hideTooltip(e);
    });
    
    clipboard.on('error', function(e) {
      setTooltip(e,'Failed!');
      hideTooltip(e);
    });
    

提交回复
热议问题