2009-07-10 9 views
5
フェードは、インターネットでのサンプルがあります出ていた

.. http://docs.dojocampus.org/dojo/fadeOut?t=tundra道場は、どのようにDIV

上のonclickイベントを行うが、私は..私は、人々が直接テキストをクリックします はその後、別の何かをしたいですテキストがフェードアウトします。

私のコードでdiv要素は、以下のショーとしてテキスト

<div id='parentNode'> 
    <div id='textDiv' onClick='whenClickAnyWhereWithinThisDiv_performFadeOut()'> 
     <div id='iconDiv'/> 
     <div id='messageDiv'/> 
    </div> 
<div> 

コードをラップがあり、私が欲しいのは、人々がtextDiv、 内の任意の場所をクリックすると、その後、全体textDivがaway..hmmフェードインします、です.....なぜ私のコードは動作しませんか?私はあなたがやろうとしているものを理解していれば、私はあなたがこれでそれを達成することができると思い

function whenClickAnyWhereWithinThisDiv_performFadeOut() { 
    ... 
    ... 
    dojo.connect(dijit.byId('textDiv'), "onClick", fadeOutAndRemove(parentNode, textDiv)); 
} 
function fadeOutAndRemove (parent, currentDiv) { 
    // just assume i can get the parent Node, and the current div, which will be textDiv  

    var objectId = currentDiv.getAttribute('id'); 
    dojo.style(objectId, "opacity", "1"); 
    var fadeArgs = { 
     node: objectId, 
     duration: 2000 
    }; 
    dojo.fadeOut(fadeArgs).play(); 

    setTimeout(function() { parent.removeChild(currentDiv);}, 2000); 
} 

答えて

8

HTML

<div id='parentNode'> 
    <div id='textDiv'> 
     <div id='iconDiv'>this is icon div</div> 
     <div id='messageDiv'>this is message div</div> 
    </div> 
<div> 

はJavaScript

// do it when the DOM is loaded 
dojo.addOnLoad(function() { 
    // attach on click to id="textDiv" 
    dojo.query('#textDiv').onclick(function(evt) { 
    // 'this' is now the element clicked on (e.g. id="textDiv") 
    var el = this; 
    // set opacity 
    dojo.style(this, "opacity","1"); 
    // do fade out 
    dojo.fadeOut({ 
     node: this, 
     duration: 2000, 
     // pass in an onEnd function ref that'll get run at end of animation 
     onEnd: function() { 
     // get rid of it  
     dojo.query(el).orphan() 
     } 
    }).play() 
    }); 
}); 

クリックはbuです

私はあなたの質問を誤解している場合、私に教えてください、私は更新します:それはここでtextDiv.

でキャッチすることがありますいくつかの有用なリンクですアップbble私の答え。お役に立てれば。

関連する問題