GithubHelp home page GithubHelp logo

elefixed's Introduction

介绍

eleFixed是一款非常简单的使用动画来固定元素的插件(最常见的作用就是固定table的thead)

它可以同时固定多个HTMLElement而不用额外监听多个事件,而且你也可以随时删除某一个监听对象或者直接把eleFixed从你的网页中移除

使用

当你引入eleFixed.js的时候,它就已经帮你在全局定义好了eleFixed对象并监听scroll事件(仅仅一个);

以下为全局eleFixed对象的描述:
eleFixed对象 描述
targets Array,用来存放多个需要固定的target对象,target对象格式见下表
push Function,接受一个target对象并推送元素到targets数组中
delete Function,从targets中删除指定的HTMLElement,只需要传入需要删除的HTMLElement对象
destory Function,移除eleFixed的监听事件、并删除eleFixed对象
eleFixed.push需要传入的对象(targrt)描述:
target对象 描述
target HTMLElement,接收你想固定的元素,比如 document.getElementsByTagName('thead')[0]
offsetTop Number,此元素距离顶部多少像素时开始固定在顶部, 比如 200 (无需单位)
插入target:
    <table class="table">
        <thead>
            <!-- some titles here -->
        </thead>
        <tbody>
            <!-- some elements here -->
        </tbody>
    </table>
    <script src="./eleFixed.min.js"></script>
    <script>
        // add an instance
        eleFixed.push({
            target: document.getElementsByTagName('thead')[0], // it must be a HTMLElement
            offsetTop: 210 // height from window offsetTop
        })
    </script>
效果预览:

image

删除元素:
<script>
    // delete an instance
    eleFixed.delete(document.getElementsByTagName('thead')[0])
</script>
移除eleFixed:
<script>
    // destory eleFixed
    eleFixed.destory()
</script>

elefixed's People

Contributors

kenyeec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

elefixed's Issues

请教实现表头上方添加一button后,button和表头均固定

你好,多谢你的code,我在本地使用chrome已经test成功,赞一个!

我想在表格上方添加一个button,然后上拉页面时,button和表头相对位置不发生变化,且均固定在页面顶部,请问如何实现?

如果赐教,不胜感激~

滚动页面后刷新页面,可以执行eleFixed.handler()来实现显示表头

感谢作者的插件,满足功能哈,,

滚动页面后,再刷新页面,这时,表头没有出来,查阅源代码发现关键函数handler();
嗯,页面加载后执行eleFixed.handler(),即可手动显示表头。

如:
//固定表头 var $jfTableHead = $("#jfTableHead"); eleFixed.push({ target: $("#jfTableHead")[0], offsetTop: $jfTableHead.offset().top - 66 }); //浏览器滚动后,刷新浏览器时,重新将表头呈现出来 eleFixed.handler();

有个问题想请教一下

您好,如果表格高度固定,表格内容滚动,您的插件要怎么在这种情况下固定表头?我使用的时候,只有在页面滚动的时候才能表头固定。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.