【问题标题】:Waypoint to fire 30px from bottom of screen从屏幕底部发射 30px 的航点
【发布时间】:2019-08-11 22:50:08
【问题描述】:

当一个部分距离底部 30 像素时,我试图触发一个航路点。

我尝试复制下面的航路点并将偏移设置为(calc 100vh-30px),但它不起作用。

我看到 Waypoints 有一个“视野底部”偏移,但有人知道如何从底部发射 30 像素的东西吗?

当距离顶部 30 像素时,下面的航路点完全符合我的要求,但我怎么还能让这个火距离底部 30 像素?

基本上我希望一个项目在距离顶部 30 像素或距离底部 30 像素之前不可见。

var $customhr = $('.custom-hr');

$customhr.waypoint(function (direction) {
    if (direction == 'down') {
    $customhr.addClass('js-custom-hr-vanish');
    } else {
    $customhr.removeClass('js-custom-hr-vanish');
    }   

}, { offset:'30px' });

CSS

.custom-hr {
    opacity: 1;
}

.js-custom-hr-vanish {
    opacity: 0;
}

【问题讨论】:

    标签: javascript jquery-waypoints


    【解决方案1】:

    还没用过jQuery waypoint,你可以试试看:

    let vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
    vh -= 30;
    
    const $customhr = $('.custom-hr');
    
    $customhr.waypoint(function (direction) {
        if (direction == 'down') {
        $customhr.addClass('js-custom-hr-vanish');
        } else {
        $customhr.removeClass('js-custom-hr-vanish');
        }   
    
    }, { offset: vh + 'px' });
    

    【讨论】:

    • 谢谢 - 这实际上非常适合底部(尽管我切换了添加和删除类),但是当我直接在我的下面添加代码时,我收到错误 Uncaught SyntaxError: Identifier '$customhr' 已经被声明 是否可以将两者合并为一个函数?
    • 其实我解决了! - 我刚刚删除了第二个声明。现在看来很明显。谢谢!
    猜你喜欢
    • 2020-03-06
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多