Intro.js更改工具提示位置

Intro.js change tooltip position

本文关键字:工具提示 位置 js Intro      更新时间:2023-09-26

我在我的网站上使用intro.js进行浏览。我使用bottom作为默认的工具提示位置,但有没有一种方法可以在教程开始后更改工具提示的位置?

这是我的代码:

tourPluginObject=introJs();
    tourPluginObject.onchange(function(targetElement) {
      if($(targetElement).attr("data-step")==5 && enteredStepFive==false){
        enteredStepFive=true;//I entered a step five, so mark this
        tourPluginObject.setOption('tooltipPosition','left');//Set new tooltip position
        tourPluginObject.setOption('data-position','left');//Set new tooltip position
        tourPluginObject.refresh();//Refresh layout
      }
    });
    tourPluginObject.setOptions({'tooltipPosition': 'bottom' });//Set default tooltip position
    tourPluginObject.start();//Start tour

如果你可以修改html,你可以在元素5上添加数据属性data-position="left",其他的没有位置,或者都设置为"bottom"。

这样,步骤5将具有所需的位置,而无需在运行时对其进行修改。