asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
/***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 汪杰 阅读(168) 评论(0)  编辑 收藏 引用 所属分类: javascript
只有注册用户登录后才能发表评论。

<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 468991
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜