2013-06-24 29 views
-2

我想有一個圖像塊文本塊 上覆蓋文本塊即圖像塊當我在圖像中單擊它應該顯示的文本塊和圖像塊變隱藏(可能會擴展文本塊以顯示內容)。顯示文本塊上單擊圖像塊

註文格應該是在圖像的div並單擊它應該顯示和圖像將隱藏圖像隱形:

JAVASCRIPT:

$(function(){ 
    $('.close').click(function(){ 
     $('#textDiv').show(); 
     $('#imageDiv').hide(); 
    }); 
}) 

HTML:

<div id="imageDiv" > 
    <a href="#" class="close">Close <img src="images/close.png" class="close"></a> 
</div> 

<div id="textDiv" style="display:none;">This is the text for the image </div> 
+1

你能更具體一點嗎?你有任何代碼嗎? – jackweinbender

+0

感謝您的回覆 - 請注意,文本div應該是在圖像div下不可見的,並且點擊它應該顯示的圖像並且圖像將被隱藏起來 $(function(){ $('。close')。click(function( ){ \t $( '#textDiv')顯示(); $( '#imageDiv')隱藏(); });} )

js4learn

回答

0

你要這樣,檢查DEMO http://jsfiddle.net/yeyene/gNQVR/1/

JQUERY

$('#imageDiv img').on('click', function(){ 
    $(this).hide(); 
    $(this).siblings('#textDiv').show(); 
}); 
$('#textDiv .close').on('click', function(){ 
    $(this).parent('#textDiv').hide(); 
    $(this).parent().siblings('img').show(); 
}); 

HTML

<div id="imageDiv" > 
    <img src="http://wallpaper-fullhd.com/wp-content/uploads/2013/03/at-the-beach-hd-wallpaper-1920x1200.jpg" class="close" width="200" height="200"> 
    <div id="textDiv"> 
     <a class="close">x</a> 
     This is the text for the image. ...</div> 
</div> 
+0

Thanks-這部分是滿足我的要求,但不是切換效果,我需要在關閉文本框和滾動條的文本塊上有關閉按鈕文本塊中的代碼會有幫助 – js4learn

+0

完成,檢查更新演示http://jsfiddle.net/yeyene/gNQVR/1/ – yeyene

0

做這樣的事情:http://jsfiddle.net/rBxeY/

$('div').click(function(){ 
    $('div').toggleClass('active'); 
}); 

HTML

<div id="imageDiv" class="active"> 
    <a href="#" class="close">Close <img src="images/close.png" class="close" /></a> 
</div> 

<div id="textDiv" >This is the text for the image </div> 

CSS

.active{ 
    display: none; 
}