2012-02-14 92 views
0

下午好, 當用戶點擊鏈接時,我很難將導航鏈接設置爲激活狀態。 我有一個header.php文件,其中包含nav和lavalamp id。 header.php包含在每個頁面中。當我點擊「關於」頁面鏈接時,該行仍保留在「主頁」鏈接的默認位置。如果有幫助,我在php中運行。jQuery Lavalamp激活狀態下的問題

感謝您的幫助...謝謝。

的header.php文件包含以下的html:

<div id="nav" class="grid_9 push_3"> 
<ul class="lavaLamp" id="lavaLampLine"> 
     <li><a href="index.php">HOME</a></li> 
    <li><a href="about.php">ABOUT US</a></li> 
    <li><a href="product.php">SUPPORT</a></li> 
    <li><a href="blog">OUR BLOG</a></li> 
     <li><a href="contact.php">CONTACT US</a></li> 
</ul><!-- end menu --> 
</div><!-- end nav --> 

的CSS:

/*樣式爲整個LavaLamp的菜單*/

.lavaLamp { 
    position: relative; 
    height:15px; 
    width:421px; 
    margin:3px 0; 
    padding:80px 0 0 0; 
/* overflow: hidden; */ 
} 
/* Force the list to flow horizontally */ 
.lavaLamp li { 
    float:left; 
    list-style:none; 
} 
/* Represents the background of the highlighted menu-item. */ 
.lavaLamp li.back { 
    border-bottom:4px solid #3A7CB8; 
    width:9px; 
    height:15px; 
    top:90px; 
    position:absolute; 
    z-index:8; 
} 

.lavaLamp li.back .left { 
    border-bottom:4px solid #3A7CB8; 
    height:15px; 
    overflow:hidden; 
margin-right: 5px; /* 5px is the width of the rounded shape */ 
} 
/* Styles for each menu-item. */ 
.lavaLamp li a { 
    font-size:16px; 
    font-weight:normal; 
    text-decoration:none; 
    display:inline; 
    color:#095BA6; 
    text-align:center; 
    margin: auto 12px; 
    display: block; 
    float: left; 
    cursor:pointer; 
    outline: none; 
    z-index:10; 
    height:30px; 
    position:relative; 
} 

.lavaLamp li a:hover, .lavaLamp li a:active, .lavaLamp li a:visited { 
    border: none; 
} 
.active { 
    border: none; 
    color:#000000; 
    font-weight:bold; 
} 

回答

2

使用PHP if/else語句將類「current」添加到您正在使用的li。

類似:

<li <?php if(strpos($_SERVER["PHP_SELF"],"index.php") !== false) echo 'class="current'; ?>><a href="index.php" >HOME</a></li> 

每個立,變更 「的index.php」 到任何文件名是。這是非常低效的......你也可以做這樣的:

<?php 
$parts = Explode('/', $_SERVER["PHP_SELF"]); 
$currentFile = $parts[count($parts) - 1]; 
?> 

,然後在每個L1,你可以說:

<li <?php if($currentFile == "index.php") echo 'class="current'; ?>><a href="index.php" >HOME</a></li> 

(來源:http://www.scriptygoddess.com/archives/2007/07/13/use-php-to-get-the-current-pagefile-name/

+0

謝謝!我會試一下 :) – telo78 2012-02-14 21:50:05