Jump to content
Sign in to follow this  
vavilovas

[Решено] Не получается выделить активный пункт меню

Recommended Posts

Нашел подобные темы, но не смог сделать правильно...

Вобщем главное горизонтальное меню:

<div id="menu">
  <ul>
    <li class="navi"><a href="index.php?route=common/home">ГЛАВНАЯ</a> </li> 
    <li class="navi"><a href="samovyvoz">САМОВЫВОЗ</a> </li>
    <li class="navi"><a href="dostavka">ДОСТАВКА</a> </li> 
    <li class="navi"><a href="contact">КОНТАКТЫ</a> </li>
    <li class="navi"><a href="garantii">ГАРАНТИИ</a> </li> 
    <li class="navi"><a href="akcii">АКЦИИ</a> </li>
    <li class="navi"><a href="index.php?route=checkout/cart">КОРЗИНА</a> </li>
    <li class="navi"><a href="index.php?route=checkout/checkout">ОФОРМЛЕНИЕ ЗАКАЗА</a> </li>

</ul>

Как выделить активный пункт меню?

 

Пробовал вот этот метод, который обсуждался на форуме:

#menu > ul > li > a.active {
background: url('../image/menulh.png') center center no-repeat;
height: 100px;
min-width: 124px;
margin-top: -14px;
}

 

 

в хидер

 

<script type="text/javascript">
$(document).ready(function(){
var url=document.location.href;
$.each($("#menu a"),function(){
if(url.indexOf(this.href)>=0){
$(this).addClass('active');
};
});
});
</script> 

В этом случае выделяется не только активный пункт, но и "Главная"

Share this post


Link to post
Share on other sites

Вопрос решил:

<script type="text/javascript">
$(document).ready(function(){
$('#menu > ul > li >a').each(function () {
  if($(this).attr('href') == location.href) $(this).addClass('Active');
});
});
</script>
<style>
.Active{
color: #ffd333 !important;
}
</style> 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.