Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

toggle - Text based game with hide/show text (Yes/No)

I'm not a coder but I'm trying to figure out how to create a website for the manifesto of play. The Idea is that when you read the manifesto you can play it by selecting yes-no and showing hidden section and going to it with an anchor link, with multiple steps.

https://manifestodelgioco.it

<p>
Do you want to play?
</p>

<a href="#iwanttoplay" class="js-toggle-visibility" data-toggle="iwanttoplay">Yes</a>

<a href="#idontwanttoplay" data-toggle="idontwanttoplay" class="js-toggle-visibility">No</a>

<div class="nascosto" id="iwanttoplay">I want to play</div>

<div class="nascosto" id="idontwanttoplay">Bye Bye</div>

Scritp

$(document).on('click', '.js-toggle-visibility', function(e) {
    e.preventDefault();
  var $divToToggle = $('#' + $(this).data('toggle'))[0];
  setTimeout(function() {
    if ($divToToggle.style.display == 'block') {
      $divToToggle.style.display = 'none';
    } else {
      $divToToggle.style.display = 'block'
    }
  })
})

css

.nascosto {
  display:none;
}

This seems to work: https://jsfiddle.net/6ze7s3ax/1/

The problem that I have is that on the theme I'm using on Wordpress I'm not able to associate the data-toggle="xx" to the button neither in the html.

Is there a possibility to edit this script to be able to use a class or id instead of the data toggle to have the same functionality?

Thanks

question from:https://stackoverflow.com/questions/65900802/text-based-game-with-hide-show-text-yes-no

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...