2016-04-13 22 views
0
#branchID pool 
branch0 = "This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text." 
branch1 = "This is a second wall of text." 
branch2 = "This is a third wall of text." 

#classes section 
    #pulls text from pools above. 
branch = (name, branchid)-> 
    stringID = String(branchid) 
    document.write("<h1 id=\'#{stringID}\'>#{name}</h1>") 
    document.getElementById(stringID).onclick = -> 
    document.write(branchid) 

#This is where the game goes. It will be built with conditionals 
window.onload = -> 
    branch('Start', branch0) 

Kahve tarayıcısı kullanarak "kendi maceranı seç" oyununa dayalı bir tarayıcı oluşturuyorum. Yukarıdaki, şimdiye kadar sahip olduğum kod. Bir HTML öğesi oluşturur ve tıklandığında, sayfaya bir metin dizisi dev bir blok halinde yazılır.Cümlelerin geniş bir dizede görüntülenmesi tek seferde bir tıklama

Sorum, bir kerede yalnızca bir cümle yüklendikten sonra tıklatıldığında, sonraki cümle yüklendikten sonra, sonraki satırın içinde kalan bir şey kalmayıncaya kadar nasıl yapabilirim?

cevap

1

Sana (umarım) istediğini yaptığı üs olarak kodunuzu kullanarak sizin için bir demo yaptı gerçekleştirmek için deneyin ne olduğunu gerçekten emin değilim iken:

https://jsfiddle.net/Exinferis/qhr7wjmu/

#branchID pool 
firstBranch = [ 
    "This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text." 
    "This is a second wall of text." 
    "This is a third wall of text." 
] 

currentStep = 0 

#classes section 
    #pulls text from pools above. 
branch = (event)-> 
    if firstBranch[currentStep]? 
    document.getElementById("text").innerHTML = firstBranch[currentStep] 
    currentStep++ 

#This is where the game goes. It will be built with conditionals 
window.onload = -> 
    document.getElementById("nextbtn").onclick = branch 
+0

Çok teşekkür ederim. Bu çok yardımcı. – bryanwillis7

İlgili konular