仅在滚动时修复div并取决于父div高度

时间:2022-11-11 21:26:18

I want to fixed the left and right div while only scrolling. It only fixed while scrolling and depends upon the parent div. I want to do some like this. On that website, category div on left side, is fixed while scrolling and it fixed only within the parent div. Not exceed on the div.

我想固定左右div而只是滚动。它只在滚动时固定并取决于父div。我想做这样的事。在该网站上,左侧的类别div在滚动时固定,并且仅在父div中固定。不超过div。

Here my sample plunkr. I want to do same thing in my website too fixed the both left and right div. Is it possible to done by angularjs instead of jquery?

在这里我的样品plunkr。我想在我的网站上做同样的事情,修复了左右两个div。是否可以通过angularjs而不是jquery来完成?

can anyone help for me?

任何人都可以帮我吗?

1 个解决方案

#1


0  

Im not sure if it can be done using angularjs as i've not really looked into it but it can easily be done using

我不确定它是否可以使用angularjs完成,因为我没有真正研究它,但它可以很容易地使用

var fixmeTop = $('.fixme').offset().top; // get initial position of the element

var fixmeTop = $('。fixme')。offset()。top; //获取元素的初始位置

$(window).scroll(function() { // assign scroll event listener

$(window).scroll(function(){//分配滚动事件监听器

var currentScroll = $(window).scrollTop(); // get current position

if (currentScroll >= fixmeTop) {           // apply position: fixed if you
    $('.fixme').css({                      // scroll to that element or below it
        position: 'fixed',
        top: '0',
        left: '0'
    });
} else {                                   // apply position: static
    $('.fixme').css({                      // if you scroll above it
        position: 'static'
    });
}

});

});

#1


0  

Im not sure if it can be done using angularjs as i've not really looked into it but it can easily be done using

我不确定它是否可以使用angularjs完成,因为我没有真正研究它,但它可以很容易地使用

var fixmeTop = $('.fixme').offset().top; // get initial position of the element

var fixmeTop = $('。fixme')。offset()。top; //获取元素的初始位置

$(window).scroll(function() { // assign scroll event listener

$(window).scroll(function(){//分配滚动事件监听器

var currentScroll = $(window).scrollTop(); // get current position

if (currentScroll >= fixmeTop) {           // apply position: fixed if you
    $('.fixme').css({                      // scroll to that element or below it
        position: 'fixed',
        top: '0',
        left: '0'
    });
} else {                                   // apply position: static
    $('.fixme').css({                      // if you scroll above it
        position: 'static'
    });
}

});

});