2011-05-31 73 views
1

我一直在攻擊這兩個星期。可以獨立顯示/隱藏。我如何隱藏節目?

我找到了切換顯示/隱藏的方法。但是每幅圖像都位於下一幅圖像的頂部,因此如果未打開圖像未關閉,則不會顯示其他切換的圖像,因爲它們位於其下方。

以下是基本JS:

<script type="text/javascript"> 
animatedcollapse.ontoggle=function($, divobj, state){ 
} 
animatedcollapse.init() 
</script> 

<script type="text/javascript"> 
animatedcollapse.addDiv('profile','hide=1') 
animatedcollapse.addDiv('photo','hide=1') 
animatedcollapse.addDiv('sabout','hide=1') 
animatedcollapse.addDiv('copy','hide=1') 
animatedcollapse.init() 
</script> 

它在這裏被用作如下:

<div align="center"> 
    <a href="javascript:animatedcollapse.toggle('profile')" title="Profile" border="0">< img src="img here.png" srcover="img here" srcdown="img here" height="50px" width="96px"></a> 
</div></div> 

<div id="mask"> 

    <div id="profile" class="nah"> 
     <a name="profile"></a> 
     <div class="contentp"> 
     <div align="center"> 
     <div class="close"><div align="right"><a id="aclose" href="javascript:animatedcollapse.toggle('profile')" title="Close"><span>CLOSE ME</span></a></div></div> 

      < img src="img here" border="0"> 

     </div></div> 
    </div> 

乘上的 「頁面」 的數量。 「頁面」是被稱爲div的另一個圖像,滑入到要查看的位置,並在單擊close時放開。我想擺脫關閉按鈕,只是當另一個div切換時隱藏當前div。這可能嗎?

爲了獲得它的完整感受,這裏是我個人地獄的開始:http://www.lantiis.com ..我真的只想要一個漂亮簡單的迷你網站,流量很大,並且很容易爲極端初學者導航。現在,即使中間用戶也被關閉按鈕困惑,顯然不知道點擊它(所以他們只能看到第一個圖像爲PROFILE)...

所有的幫助和線索表示讚賞。 Lantiis

+0

是的,按照建議檢查jquery,是一個很棒的定時器。但是,關於您的網站,我有幾點建議:在android/webkit瀏覽器上查看,您可能會發現它已損壞。此外,爲了避免這樣的問題,使用逐步增強,您的網站很簡單,你不應該需要依靠js。我已經做了一些簡單的工作,可以在我的網站@ royronalds.com上爲您工作。 – Kzqai 2011-05-31 02:33:58

回答

3

我注意到,你在jQuery的,包括(與你所標記的話)在您的網站,所以我會建議一個jQuery的解決方案。只是要詳細闡述zod的迴應。

$(document).ready(function() { 
    $('#idOfYourMenuItem').click(function() { 
    //Hide the other images 
    hideAll(); 

    //Show the image that you want 
    $('#divOfTheRelatedImage').show(); 
    } 
    //Bind your other menu items here 
    //$('#idOfYourMenuItem2').click etc... 

    hideAll(); 

    //Show your first page here somewhere 
    $('#divOfFirstPage').show(); 
}); 

function hideAll() { 
    $('#divOfTheRelatedImage').hide(); 
    $('#divOfTheRelatedImage2').hide(); 
} 

這是一個非常簡單的方法,應該可以幫助您入門。如果您需要更多幫助,請告訴我。

2

你想要一個簡單的標籤導航?

看看這個:http://www.kminek.pl/lab/yetii/或在網上搜索

聯JavaScript是壞的 「JavaScript的標籤導航」 閱讀更多關於unobstrusive JavaScript編程這裏:

而且如另一篇文章中所建議的那樣,您可以從使用庫中受益,情況下,jqueryhttp://www.smashingmagazine.com/2008/09/16/jquery-examples-and-best-practices/

0

我認爲這會讓你的生活變得很容易使用jQuery,並使用你的用戶點擊的<a>標籤作爲關鍵字來顯示和隱藏id相同的div名稱。這樣可以更輕鬆地跟蹤正在發生的事情並輕鬆添加/刪除項目。

的腳本是:

$('#mask > div:first-child').show(); 
$('#top a').click(function() { 
    var keyterm = $(this).attr('title'); 
    $('#mask > div').hide(); 
    $('div[id=' + keyterm + ']').slideDown('slow'); 
}); 

我已爲你的HTML的簡化版本到jfiddle所以你可以看到它的工作(jfiddle

請注意,這種方法的工作,你必須對您在「mask」div中切換的div名稱進行較小的編輯,以便它們與您點擊的<a>標籤的標題相匹配(所以'版權'應該與'版權'等匹配)