/***current artical***/
var curObj = $(".artical")[0], fTop = curObj.offsetTop, clickObj = null;
$(curObj).addClass("curRecord");
$(window).scroll(function(){
$(".artical").each(function(i){
var curLimit = {start: i ? this.offsetTop - fTop : 0, end: i ? this.offsetTop - fTop + this.offsetHeight: this.offsetHeight} ;
var scrollLimit ={start: $(window).scrollTop(), end: $(window).scrollTop() + $(window).height()};
var diffH = curDiffH = 0;
if(curObj.offsetTop - fTop < scrollLimit.start && curObj.offsetTop - fTop + curObj.offsetHeight > scrollLimit.start){
if(curLimit.start > scrollLimit.start && curLimit.end > scrollLimit.end && curLimit.start < scrollLimit.end){
diffH = curObj.offsetTop - fTop + curObj.offsetHeight - scrollLimit.start;
curDiffH = scrollLimit.end - curLimit.start;
}
}else if(curObj.offsetTop - fTop > scrollLimit.start && curObj.offsetTop - fTop < scrollLimit.end && curObj.offsetTop - fTop + curObj.offsetHeight > scrollLimit.end){
if(curLimit.start < scrollLimit.start && curLimit.end > scrollLimit.start){
diffH = scrollLimit.end - curObj.offsetTop + fTop;
curDiffH = curLimit.end - scrollLimit.start;
}
}
if(curLimit.start >= scrollLimit.start && curLimit.end <= scrollLimit.end ||
curLimit.start < scrollLimit.start && curLimit.end >= scrollLimit.end ||
curDiffH && diffH && curDiffH > diffH){
$(curObj).removeClass("curRecord");
$(this).addClass("curRecord");
curObj = this;
return false;
}
});
});
function clickFunc(){
clickObj = this;
if(this.offsetTop - fTop > $(document).height() - $(window).height()){
$(curObj).removeClass("curRecord");
$(this).addClass("curRecord");
curObj = this;
return false;
}else{
$(window).scrollTop(this.offsetTop - fTop);
}
};
$(".artical").click(clickFunc);
posted on 2008-12-05 14:31
汪杰 阅读(167)
评论(0) 编辑 收藏 引用 所属分类:
javascript