导航如果在当前页面则保持高亮显示

发布于 2024-10-05 07:10:12 字数 1288 浏览 4 评论 0原文

好吧,我的问题是下一个,我得到了一个带有 jQuery 动画 的导航,当将鼠标悬停在 << 时,会出现一个绿色滑块。 li > 标签。

当是当前页面时,突出显示状态是保持向下,但是当我 mouseOut 时它返回到顶部,这是自然行为。

我知道如何告诉 jQuery“如果”是 $current 幻灯片,不要 mouseOut

也许你可以查看代码

我得到了一个变量。

$current = 当前页面。

jQuery 代码:

 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);

编辑: 好的,我从 ircmaxell 获得了一些帮助,

我在标头中的 css 之后添加了此操作,以便我可以获得值当前页右。

<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');}
 };

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

when is current page, the hightlight state is to stay down, but when I mouseOut it returns to the top, thats the natural behaviour.

I what to know how can I tell jQuery to "if" is $current slide, don't mouseOut

Maybe u can check out the code better in the website

I got a variable.

$current = the 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:
Ok, I get some help from ircmaxell

I add did this after my css in the header so I can get the value of currentPage right.

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

Then change this code to the if statement.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2024-10-12 07:10:12

您可以通过在 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)但是如果您选择的 id 与页面匹配,它应该禁用任何悬停/释放操作。这样它就保持“无动画”。

编辑

由于您在 PHP 方面遇到问题:

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

编辑更多...

好吧,看来您

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

在正确的位置添加时遇到了问题。我会将其放入您的主体中,只要您打开 时它位于主页上即可。我希望这有帮助,我开始觉得你在不知道任何 php 或 javascript 的情况下试图破解这个。

如果您喜欢这个答案,请标记为“答案”(绿色复选标记),谢谢。

You could easily do this by setting a flag in your JS, something like:

var currentPage = "nInicio"

Then in then 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');
  }
 }

My code might not be correct (just typed it psudo like real quick) but it should disable any hover / release actions if your selected id is the one that matches the page. That way it stays 'un-animated'.

EDIT

Since you are having trouble with the PHP side of it:

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

EDIT EVEN MORE...

Okay it seems you are having trouble adding the

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

in the right place. I would put this into your main body, as long as it is on the main page right when you open the <body>. I hope that helps, I am starting to feel like you are trying to hack this not knowing any php or javascript.

If you like this answer, please mark as 'answer' (green checkmark) thanks..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文