滚动问题上的固定元素

时间:2015-04-28 16:47:25

标签: javascript jquery html css

所以,我正在尝试重现这个美丽投资组合的主要滚动效果:http://melaniedaveid.com/

我在Codyhouse上遵循了这个教程:http://codyhouse.co/gem/fixed-background-effect/

并提出了以下Javascript功能。

$(window).scroll(function(){

var scrollTop = $(window).scrollTop(),
    windowHeight = $(window).height(),
    contentright1 = document.getElementById('contentright1');

function checkScroll(id) {
    var offset = scrollTop - $(id).offset().top;

    if (offset >= 0 && offset < windowHeight) {
        $(id).addClass('fixed_content');

        if ((scrollTop/2) <= windowHeight) {
            $(id).removeClass('fixed_content');

        }
    }
    else {
        $(id).removeClass('fixed_content');
    }
};

checkScroll(contentright1);

fidex_content类应用以下CSS:

.fixed_content {
position: fixed;
top:0; }

正如您所看到的,我的主要问题是,当我首先回到元素的位置时,我无法移除此类。

0 个答案:

没有答案
相关问题