如何在Bootstrap Affix下获取当前元素? [英] How to get the current element under Bootstrap Affix?

查看:89
本文介绍了如何在Bootstrap Affix下获取当前元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取当前固定元素的同级元素的偏移量.这可能吗?我希望使用类似的东西:

I need to get the offset of a sibling of the current affixed element. Is this possible? I was hoping to use something like:

$('.affixed').affix({
    offset: {
        top: 150,
        bottom: function() {
            return $(this).siblings('p').offset().top;
        }
    }
});

但是this只是一个{top:X, bottom:Y}对象,而不是实际的元素.我有多个需要动态附加的.affixed元素.

But this is just a {top:X, bottom:Y} object and not the actual element. I have multiple .affixed elements that I need to affix dynamically.

推荐答案

bottomtop函数将通过初始化集合的原始元素.

The bottom and top functions will pass through the original element that initialized the collection.

对于多个元素,您必须将affix包装在原始集合的each中.

For multiple elements, you'll have to wrap affix in each from the original collection.

$('.affixed').each(function() {
    $(this).affix({
        offset: {
            top: 150,
            bottom: function(e) {
                return $(e).siblings('p').offset().top;
            }
        }
    });
});

这篇关于如何在Bootstrap Affix下获取当前元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆