0

目前,我的一页网站有 4 个不同的部分,它们的高度为 100%(主容器)。我可以使用箭头键滚动到每个部分。当我单击它们时,我的导航链接也会保持突出显示。问题是通过向下滚动页面我的 jQuery 不记得位置。此外,如果我要单击导航链接并滚动到下一部分(使用鼠标),链接将保持突出显示并且不会更改为当前部分。帮助将不胜感激。

这是我的小提琴http://jsfiddle.net/phUxg/2/

jQuery

$(document).ready(function() {
$(function() {
var lengthDiv = $('.desktop').find('li').length;
var current = 0;
$('a').bind('click',function(event){

var $anchor = $(this);
current = $anchor.parent().index();

$('html, body').stop().animate({
    scrollTop: $($anchor.attr('href#')).offset().top
}, 1500,'easeInOutExpo');
/*
if you don't want to use the easing effects:
$('html, body').stop().animate({
    scrollTop: $($anchor.attr('href')).offset().top
}, 1000);
*/
event.preventDefault();
});
$(document).keydown(function(e){if($(':focus').length <= 0)e.preventDefault()})
$(document).keyup(function(e){
    var key = e.keyCode;
    if(key == 38 && current > 0){
        $('.desktop').children('li').eq(current - 1).children('a').trigger('click')
    }else if(key == 40 && current < lengthDiv){
        $('.desktop').children('li').eq(current + 1).children('a').trigger('click')
    }
})
});

$(document).ready(function() {
$(".desktop a").click(function() {
$(".desktop a").removeClass("selected");
$(this).addClass("selected"); 
});
});
});
4

0 回答 0