2017-02-04 6 views
1

intro.js의 '힌트'기능을 켜거나 끌 수있는 버튼이 필요합니다.intro.js 데이터 힌트 표시 및 숨기기

표시하고 숨기기 작업 버전이 있지만 쇼는 한 번만 작동합니다. 반복적으로 작동 시키려면 어떻게해야합니까? 이 기능은 표준 데이터 인트로에 대해서는 작동하지만 데이터 힌트에는 작동하지 않습니다.

hints = [{...}, ...] 

다음, 인트로 옵션에서 힌트를 재설정 :

<div class="jumbotron"> 
    <h1 id='step1'>Hints</h1> 
    <p class="lead">Adding hints using JSON + callbacks</p> 
    <a id='step2' class="btn btn-large btn-success" href="javascript:void(0);">Add hints</a> 
</div> 

function addHints(){ 
    intro = introJs(); 
     intro.setOptions({ 
     hints: [ 
      { 
      element: document.querySelector('#step1'), 
      hint: "This is a tooltip.", 
      hintPosition: 'top-middle' 
      }, 
      { 
      element: '#step2', 
      hint: 'More features, more fun.', 
      position: 'left' 
      }, 
      { 
      element: '#step4', 
      hint: "<b>Another</b> step.", 
      hintPosition: 'top-middle' 
      } 
     ] 
     }); 
     intro.onhintsadded(function() { 
      console.log('all hints added'); 
     }); 
     intro.onhintclick(function(hintElement, item, stepId) { 
      console.log('hint clicked', hintElement, item, stepId); 
     }); 
     intro.onhintclose(function (stepId) { 
      console.log('hint closed', stepId); 
     }); 
     intro.addHints(); 
    } 
$(function() { 
    $('#step2').click(function(){ 
     if ($('#step2').hasClass('clicked')) { 
      introJs().hideHints(); 
      $('#step2').removeClass('clicked'); 
     } else { 
      addHints(); 
      $('#step2').addClass('clicked'); 
     } 
    }); 
}); 

답변

0

아마 조금 해키, 그러나 이것은 나를 위해 작동은 ...

첫째, 자신의 변수로 힌트를 넣어

intro.onhintclose(function(stepId) { 
    if (document.querySelectorAll('.introjs-hidehint').length === hints.length) { 
    intro.setOptions({hints: hints}) 
    } 
}) 

숨겨진 힌트

는 introjs-hidehint의 클래스를 제공하고 있으며, document.querySelectorAll 반환합니다 모두 배열로. 배열의 크기가 힌트 배열과 같으면 인트로 옵션에서 힌트를 다시 설정하면 모든 힌트가 다시 표시되므로 다시 표시 할 수 있습니다. 대신 단지 DOM에서 intro.js의 DIV 블록을 제거 hideHints intro.js의 API 방법을 사용

0

:

var introDiv = document.getElementsByClassName("introjs-hints")[0]; 
introDiv.parentNode.removeChild(introDiv); 

(당신이 원하는 경우 jQuery로 같은 일을 할 수 있습니다.)

div가 div에서 제거되면 힌트를 표시 할 때 addHints 메서드를 사용하는 것처럼 힌트를 다시 초기화하면 작동합니다.