Maintain navigation Highlight if on current page

Ok, my problem is the following, I got navigation with animation in jQuery , a green slider that comes down when you hover <li> .

when the current page, the hightlight state should remain in place, but when I am in, it returns to the top, this is a natural behavior.

I know how I can tell jQuery that "if" is the current current slide, not mouseOut

Perhaps you can check the code better on the website

I have a variable.

$ current = current page.

JQuery Code:

 var navHover = function () {
  $("#S" + this.id).animate({top: '-40px'}, 300, 'swing')
  $("#A" + this.id).animate({paddingTop: '30px'}, 300, 'swing').animate({paddingTop: '45px'}, 300, 'swing')
  $("#I" + this.id).animate({top: '-10px'}, 300, 'swing').animate({top: '0px'}, 300, 'swing')
 }
 var navRelease = function () {
  $("#S" + this.id).animate({top: '-130px'}, 300, 'swing');
 }

 $('#navInside .topLevel').hover(navHover, navRelease);

EDIT: Alright, I get some help from ircmaxell

css , currentPage.

<script type="text/javascript">
var currentPage = "<?php echo substr($current, 1) ?>";
</script>

if.

 var navRelease = function () {
 if(this.id != currentPage){
 $("#S" + this.id).animate({top: '-130px'}, 300, 'swing');}
 };
+3
1

, JS, :

var currentPage = "nInicio"

navHover:

 var navHover = function () {
  if(this.id != currentPage){
   $("#S" + this.id).animate({top: '-40px'}, 300, 'swing')
   $("#A" + this.id).animate({paddingTop: '30px'}, 300, 'swing').animate({paddingTop: '45px'}, 300, 'swing')
   $("#I" + this.id).animate({top: '-10px'}, 300, 'swing').animate({top: '0px'}, 300, 'swing')
  }
 }
 var navRelease = function () {
 if(this.id != currentPage){
  $("#S" + this.id).animate({top: '-130px'}, 300, 'swing');
  }
 }

( psudo ), hover/release, , . , " ".

PHP:

<script>
  var current = "<?php echo substr($current, 1) ?>";
</script>

...

, ,

<script>
  var current = "<?php echo substr($current, 1) ?>";
</script>

. , , <body>. , , , , php javascript.

, "" ( ) ..

+2

Source: https://habr.com/ru/post/1777994/


All Articles