2012-07-02 173 views
1

我需要一些适当的滚动解决方案为底部的标签。工作代码可以查看在:this linkjquery滚动到页面底部

检查网页设计的页脚链接等jQuery代码是:

$(document).ready(function() {  
    $('.locations div').hide(); 
    $('#footer ul.left li a').click(function() { 
     $('#footer ul.left li').removeClass('active'); 
     $(this).parent().addClass('active'); 
     var currentTab = $(this).attr('href'); 
     $('.locations div').hide("normal"); 
     $(currentTab).show("normal"); 
     $("html, body").animate({ 
      scrollTop: $(document).height() 
     }, "normal"); 
     return false; 
    });  
});​ 

的问题是:一个链接滚动窗口上点击向下的情况下正确,但当另一个链接被点击时,页面中会出现一个小混蛋。也再次点击相同的链接。滚动上升但内容不隐藏。

回答

0

我只在第二次点击相同的链接时才看到问题。尝试检查链接是否已被点击,通过检查它是否有你的课程'活跃'。如果它已经被点击时,不重新加载任何东西:

$(document).ready(function(){ 
$('.locations div').hide(); 
    $('#footer ul.left li a').click(function(){ 
    if (!$(this).hasClass('active')){ //If it HASN'T been clicked yet 
    $('#footer ul.left li').removeClass('active'); 
    $(this).parent().addClass('active'); 
    var currentTab = $(this).attr('href'); 
    $('.locations div').hide("normal"); 
    $(currentTab).show("normal"); 
    $("html, body").animate({ scrollTop: $(document).height() }, "normal"); 
    return false; 
    } 
}); 
}); 

看到我的小提琴here

0

你的点击处理程序代码可以从所有李时珍分解为以下步骤

  1. 删除类
  2. 添加类点击李。
  3. 隐藏所有信息divs。
  4. 显示点击li的信息div。

正如您所看到的,您在任何时候都显示点击li的info div。这就是为什么你有第二个问题(单击相同的链接不会隐藏信息)。

关于第一个问题,如果我们删除动画滚动到文档底部,那么挺举不在那里。只有在信息div不存在的情况下,您才可以选择实现滚动到底部,即没有“活跃”类的信息。在单击处理

find li with class active. 
- if not found 
    - add class to current li. show current li's info div. scroll to bottom. 
- if found, 
    - check whether li is same as the li we clicked on. 
    - if yes, 
     - hide the current li's info div. exit the function. 
    - if no, 
     - hide the info div for the currently active li. 
     - show the info div for the li clicked on. 

如果你需要为这个js代码

伪代码,请走中的注释。