Tooltips + Highlight Animation With Clipboard.js Click

前端 未结 2 1482
清歌不尽
清歌不尽 2020-12-13 13:57

I\'ve successfully installed clipboard.js and have gotten snippets of text to copy to the clipboard upon click. I\'m going to be nesting these snippets of text (or the \"btn

2条回答
  •  情深已故
    2020-12-13 14:46

    Seems like all you want to do is integrating Clipboard.js with a Tooltip solution.

    So here's how you can accomplish that using Bootstrap's Tooltip.

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

提交回复
热议问题