找回密码
 立即注册

QQ登录

只需一步,快速开始

Joe.xu 讲师达人认证 悬赏达人认证 活字格认证
超级版主   /  发表于:2023-8-18 14:25  /   查看:1682  /  回复:0
本帖最后由 Simon.Sun 于 2023-8-29 09:21 编辑

最近好多格友都问了,我们插件商城中的页面往上滚动,菜单就置顶悬浮的功能是怎么实现的

菜单项悬浮.gif

不得不说这个效果确实牛,所以应该不怎么好实现。真应了那句话了,越漂亮的越难得到

于是我们找了内部的开发大佬,给大家抽出了一个demo

主要的精髓其实就是在页面的加载命令中,写的核心的Js以及一个设计悬浮单元格命令的插件,
这个插件产品化之后也会上架商城
image.png304027098.png

JS代码是
const pageScrollHandler = () => {
    const isTabHeaderVisible = isElementVisible(".tab_menu");
    if (isTabHeaderVisible) {
        //tab页头可见则隐藏电梯菜单
        Forguncy.CommandHelper.executeCellCommand("隐藏电梯菜单");
        //电梯菜单隐藏的同时需要设置tab页的缺省选中页
        Forguncy.CommandHelper.executeCellCommand("设置tab页缺省选中项目");
    }
    else {
        //tab页头不可见则显示电梯菜单
        Forguncy.CommandHelper.executeCellCommand("显示电梯菜单");
    }
}

//判断dom元素是否可见
const isElementVisible = (element, fullyInView = false) => {
    const pageTop = $(window).scrollTop();
    const pageBottom = pageTop + $(window).height();
    const elementTop = $(element).offset() == undefined ? undefined : $(element).offset().top;
    const elementBottom = elementTop + $(element).height();

    if (fullyInView === true) {
        return ((pageTop < elementTop) && (pageBottom > elementBottom));
    } else {
        return ((elementTop <= pageBottom) && (elementBottom >= pageTop));
    }
}

$(window).on("scroll", pageScrollHandler);

主要的作用就是通过判断上面的菜单是否被滚动走了,如果滚动走了,
就让页面最下面的电梯菜单悬浮在页面上方

image.png257560424.png

demo的效果如下,目前还是一个毛坯房,大家使用的时候可以用css调整样式,精修就靠大家了
悬浮菜单demo效果.gif

最后附上demo(大家使用的时候切不可忽略页面单元格设置的别名,代码中需要用这个定位页面元素)
floating-demo.fgcc (4.97 MB, 下载次数: 99)

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部