multiple semantic-ui popups with target element defined in atribute of each instance

半城伤御伤魂 提交于 2019-12-13 07:19:09

问题


I have succesfully defined a popup for a clickable link element:

The element:

`<a href="{{URL::to('alerts')}}" data-tcs="#popup-1">Alerts Page</a>`

The script which triggers my popup (note the commented lines!)

$('[data-tcs]')
.popup({
// (default as in example provided on the S-UI, works well) 
// popup : $('#popup-1'),
// (attempt 1, doesn't work) 
// popup : $(this).data('tcs'),
// (attempt 2, doesn't work) 
    popup : $(this).attr('data-tcs'),
    on    : 'hover',
    delay: {
      show: 0,
      hide: 500
    },
    hoverable: true
});

The popup itself (irrelevant):

<div class="ui popup" id="popup-1"> 
  <h3>TANJ!</h3> 
  </div>

TO DO

Now the popup works well ONLY when the ID of target content is pointed directly, but... I am about to put about 10 more popups and I want to use the same script to trigger them. How I can point to the proper popup depending on the value of data-tcs attribute? My attempts were friutless.

Thx for all help.

The docs are here: http://semantic-ui.com/modules/popup.html#/examples


回答1:


Whenever you need to pass instance specific data to any plugin options the easiest way is to wrap the initialization in an each loop

Then the each loop will expose the instance as this.

When you are trying to use this currently it is the window not the element

$('[data-tcs]').each(function() {
  var $el = $(this);
  $el.popup({    
    popup: $el.attr('data-tcs'),
    on: 'hover',
    delay: {
      show: 0,
      hide: 500
    },
    hoverable: true
  });
});


来源:https://stackoverflow.com/questions/35097417/multiple-semantic-ui-popups-with-target-element-defined-in-atribute-of-each-inst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!