Pin any element within a container

Overview

jQuery.pin

Ever wanted to pin something to the side of a text? Ever needed a subtle sticky element to quietly hang around as you scroll down?

Jquery.Pin is here to help! Pin any element to the top of a container. Easily disable it for smaller screen-sizes where there's no room for that kind of shenanigans.

Usage

Include jquery and jquery pin at the bottom of your html. Then pin any element you want like this:

$(".pinned").pin()

To make a pinned element stay within an outer container, use the containerSelector option:

$(".pinned").pin({containerSelector: ".container"})

Padding can also be added around the pinned element while scrolling:

$(".pinned").pin({padding: {top: 10, bottom: 10}})

That's it - go pin all the things!

Examples

Plenty of examples Here.

License

Copyright (c) 2013, Mathias Biilmann All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Comments
  • Workaround for removed elements

    Workaround for removed elements

    When a pinned element is removed, it stays registered in elements property but there is no longer any data (https://github.com/webpop/jquery.pin/blob/gh-pages/jquery.pin.js#L50) for it.

    opened by cchantep 1
  • Add your plugin to the jQuery plugin registry

    Add your plugin to the jQuery plugin registry

    I had seen your plugin somewhere on some days ago (HN I think), but when I needed it, as usual, couldn't find it anymore. Adding the plugin to the Plugin registry will help me (and perhaps others?) find it when we need it, and thus perhaps increase popularity too :wink:

    opened by x3ro 1
  • “Uncaught TypeError: a.indexOf is not a function” error

    “Uncaught TypeError: a.indexOf is not a function” error

    its showing error with latest jquery version

    Please Replace the window load function in script line number 110 in jquery.pin.js

    $window.load(update); with $window.on('load', function(){ update});

    now it will not show any error

    opened by pioneersingh321 0
  • CSS Selector inconsistency

    CSS Selector inconsistency

    There's an inconsistency present when passing in selectors. IE, activeClass can be passed in unqualified, but containerSelector needs to be fully qualified.

    EG, this will not work

    $('.post .sidebar.lower').pin({
        padding: {
            top: 10,
            bottom: 10
        },
        activeClass: 'pinned',
        containerSelector: 'pin-parent'
    });
    

    But this does

    $('.post .sidebar.lower').pin({
        padding: {
            top: 10,
            bottom: 10
        },
        activeClass: 'pinned',
        containerSelector: '.pin-parent'
    });
    

    It could be argued that this is semantically correct, given the difference between the option names.. EG "Class" as opposed to "Selector".

    Will open a PR for this issue if no-one else gets to it first

    opened by lukerollans 0
  • Fixed header

    Fixed header

    Hi, these commits add classes to the three states(to eventually be used by css), adds an overflow:auto to pinned content that is higher than the window, and support for a fixed header.

    Last thing to be corrected, still, is to correct the following behavior: when a pinned content is in overflow, and the end of the container is reached, the pinned content should change state as soon as its normal height hits the bottom, not its current height(the overflow:auto one)

    opened by walidvb 0
  • CSS Class based on pin state

    CSS Class based on pin state

    Option to add and remove class to element being pinned as the pinning state changes. This allows CSS targeting based on if the element is being pinned or not. Passed in as an option [activeClass] when calling pin function.

    $('.please-pin-me').pin({ activeClass: 'currently-pinned' });

    opened by MikeGrace 0
  • Multiple instances, different minWidths?

    Multiple instances, different minWidths?

    Is it possible to have multiple pins but target different screen sizes - ie the equivalent of having both these on the page:

    $(".pin-1").pin({containerSelector: ".container-1", minWidth: 768});
    $(".pin-2").pin({containerSelector: ".container-2", minWidth: 1024});
    

    Many thanks for any pointers...!

    opened by FrankPrendergast 0
  • multiple pins within same container not working

    multiple pins within same container not working

    Code is below. It will pin my .one element, but ignores my attempt to pin .two and .three

    <style type="text/css">
        .one, .two, .three { 
            width: 100%;
            height: 500px;
            background-size: 100% auto;
            position: relative;
        }
        .one {
            z-index: 1 !important;
        }
        .two {
            z-index: 11 !important;
        }
        .three {
            z-index: 111 !important;
        }
    </style>
    <div class="mymain">
        <div>
        This is a nav section.<br />
        </div>
        <div class="main">
            <div class="one " >
                <h2>Section 1</h2>
                <p>Lorem ipsum dolar sit amet. Lorem ipsum blah blaah.</p>
                <p>Lorem ipsum dolar sit amet. Lorem ipsum blah blaah.</p>
            </div>
            <div class="two " >
                <h2>Section 2</h2>
                <p>Lorem ipsum dolar sit amet. Lorem ipsum blah blaah.</p>
                <p>Lorem ipsum dolar sit amet. Lorem ipsum blah blaah.</p>
            </div>
            <div class="three">
                <h2>Section 3</h2>
                <p>Lorem ipsum dolar sit amet. Lorem ipsum blah blaah.</p>
                <p>Lorem ipsum dolar sit amet. Lorem ipsum blah blaah.</p>
            </div>
        </div>
    </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
        <script src="http://enterprise.blob.core.windows.net/microsoftcloud/pih/jquery.pin.js"></script>
        <script>
    
    
        $(".one").pin({containerSelector: ".main"})
    
        $(".two").pin({containerSelector: ".main"})
        $(".three").pin({containerSelector: ".main"})
    
        </script>
    
    opened by line32 0
Owner
Webpop
Webpop
A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time.

A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time. Dropdown, navigation bu

Matthieu Bué 277 Nov 25, 2022
JavaScript micro-library: pass in an element and a callback and this will trigger when you click anywhere other than the element

Add a click listener to fire a callback for everywhere on the window except your chosen element. Installation run npm install @lukeboyle/when-clicked-

Boyleing Point 5 May 13, 2021
Lazyload images, iframes or any src* element until they are visible in the viewport.

Lazyload images, iframes or any src* element until they are visible in the viewport.

Vincent Voyer 938 Nov 15, 2022
A simple jQuery extension to make any HTML element sticky on scroll.

jquery.sticky.js A simple jQuery extension to make any HTML element sticky on scroll. Installation Just download the script and include it in your HTM

Achal Jain 2 Aug 22, 2022
Little Alpine.js plugin to add a typewriter effect to any HTML element.

⌨️ Alpine Typewriter ⌨️ An Alpine.js plugin to add a typewriter effect to any HTML element. ?? Installation CDN Include the following <script> tag in

Marc Reichel 58 Dec 28, 2022
A simple lightweight file dropzone component based on jQuery. You can easily make any existing element become a dropzone that holds files.

file-dropzone A simple lightweight file dropzone component based on jQuery. You can easily make any existing element become a dropzone that holds file

Anton Bardov 1 May 31, 2021
adds the *scrollin* and *scrollout* events to jquery, which will fire when any given element becomes (respectively) visible and invisible in the browser viewpori

jQuery.scrolling This plugin adds the scrollin and scrollout events to jquery: these events will fire when any given element becomes visible/invisible

Dark 5 Apr 7, 2021
A container-friendly alternative to os.cpus().length. Both cgroups v1 and cgroups v2 are supported.

node-cpu-count A container-friendly alternative to os.cpus().length. Both cgroups v1 and cgroups v2 are supported. Installation $ npm install node-cpu

Jiahao Lu 2 Jan 17, 2022
The invoker based on event model provides an elegant way to call your methods in another container via promisify functions

The invoker based on event model provides an elegant way to call your methods in another container via promisify functions. (like child-processes, iframe, web worker etc).

尹挚 7 Dec 29, 2022
Container Image Signing & Verifying on Ethereum [Testnet]

cosigneth An experimental decentralized application for storing and verifying container image signatures as an NFT on Ethereum cosigneth, is a decentr

Furkan Türkal 17 Jul 4, 2022
Mailbox is the predictable states & transitions container for actors.

Mailbox (turns XState Machine into a REAL Actor) Mailbox is an NPM module built on top of the XState machine, by adding a message queue to the XState

Huan (李卓桓) 40 Aug 24, 2022
ContainerMenu is an API for BDSX that allows you to create fake interactive container menus !

ContainerMenu - A BDSX API ContainerMenu is an API for BDSX that allows you to create fake interactive container menus ! Features Multiple containers

Se7en 8 Oct 28, 2022
Jugglr is a tool for managing test data and running tests with a dedicated database running in a Docker container.

Jugglr Jugglr is a tool for managing test data and running tests with a lightweight, dedicated database. Jugglr enables developers, testers, and CI/CD

OSLabs Beta 74 Aug 20, 2022
A docker container with a wide variety of tools for debugging and setting up micro-services

Frame One Software Placeholder There are numerous times during the dev ops deployments, that a placeholder container is needed. In the past, Frame One

Frame One Software 8 May 29, 2022
Public repository of assets used during editions of AWS LATAM Container Roadshow event.

LATAM Containers Roadshow This is the official repository of assets related to LATAM Containers Roadshow, an all-day customer-facing event to highligh

AWS Samples 12 Dec 6, 2022
Make text fit container, prevent overflow and underflow.

AutoTextSize Make text fit container, prevent overflow and underflow. The font size of the text is adjusted so that it precisely fills its container.

Sana Labs 10 Dec 30, 2022
Open Horizon service container demonstrating Node-RED Object Detection

service-node-red-object-detection Open Horizon service container demonstrating Node-RED Object Detection. This is an Open Horizon configuration to dep

null 4 Dec 25, 2022
Moject is a IoC container and an app factory built around the modules idea of Angular and NestJs.

Moject Moject is an IoC container and an app factory package built around the modules idea of Angular and NestJs. Usage npm install moject Use @Mo

Alexander 4 Dec 4, 2022
The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate application for learning out how to build, run and deploy a multi-container environment (docker-compose).

foodtrucks-app-docker-compose The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate applic

Selçuk Şan 3 Oct 24, 2022