动态更改标题属性

时间:2018-01-09 19:14:28

标签: javascript golden-layout

我正在尝试为GoldenLayout中的控件图标添加自定义工具提示。

到目前为止,我所做的是,我找到了每个控制器图标的类,并添加了一个名为tooltip的新属性并删除了title属性。

适用于close& open in new window,但对于minimisemaximise,我需要动态设置tooltip值,还需要删除title属性

我无法实现这一功能。请帮忙

完整代码https://jsfiddle.net/sutgfg1y/



myLayout.on('stackCreated', function(stack) {

  stack
    .header
    .controlsContainer
    .find('.lm_close') //get the close icon
    .attr('tooltip', 'Close')
    .removeAttr('title')
  stack
    .header
    .controlsContainer
    .find('.lm_popout') //get the close icon
    .attr('tooltip', 'Open in new window')
    .removeAttr('title')
  stack
    .header
    .controlsContainer
    .find('.lm_maximise')
    .attr('tooltip', 'maxi')
    .removeAttr('title')
    .click(function() {
      var maxi = stack
        .header
        .controlsContainer
        .find('.lm_maximise')
        .attr('tooltip')
      alert(maxi)
    })

});




1 个答案:

答案 0 :(得分:0)

将工具提示的当前值保存在变量中。在点击时切换该值,然后重置工具提示...

myLayout.on('stackCreated', function(stack) {
  // Keep track of the state of the tooltip
  var minMax = 'maximize';

  stack
    .header
    .controlsContainer
    .find('.lm_close') //get the close icon
    .attr('tooltip', 'Close')
    .removeAttr('title')
  stack
    .header
    .controlsContainer
    .find('.lm_popout') //get the close icon
    .attr('tooltip', 'Open in new window')
    .removeAttr('title')
  stack
    .header
    .controlsContainer
    .find('.lm_maximise')
    .attr('tooltip', minMax) // Set the starting value
    .removeAttr('title')
    .click(function() {
      // Verify what your click just did
      var maxi = stack
        .header
        .controlsContainer
        .find('.lm_maximise')
        .attr('tooltip');
      alert(maxi);

      // Toggle the tooltip
      minMax = minMax === 'maximize' ? 'minimize' : 'maximize';
      stack
        .header
        .controlsContainer
        .find('.lm_maximise')
        .attr('tooltip', minMax);
    })
});