Pin any element within a container and more
JavaScript HTML CSS
Latest commit c7ea6d7 Mar 9, 2016 @nezamy Update README.md
Permalink
Failed to load latest commit information.
css Update style.css Jan 11, 2016
js Create prettify.js Jan 10, 2016
README.md Update README.md Mar 9, 2016
index.html Update index.html Mar 9, 2016
jquery.pinBox.js Update jquery.pinBox.js Mar 9, 2016
jquery.pinBox.min.js Update jquery.pinBox.min.js Mar 9, 2016

README.md

jquery.pinBox

Pin any element within a container . for examples go to http://nezamy.com/pinBox.

Usage

1. Load jQuery and include pinBox plugin file

To use pinBox, you’ll need to make sure both the pinBox and jQuery 1.7 or higher scripts are included.

  <!--  jQuery  -->
  <script src="jquery-1.9.1.min.js"></script>
  <!--  Include pinBox plugin  -->
  <script src="js/jquery.pinBox.min.js"></script>

2. Set up your HTML

You don't need any special markup. All you need is to wrap your divs inside the container for example #pinBoxContainer and add class to your div for example .pinBox . read the code comments.

<!-- container with id -->
<div class="container" id="pinBoxContainer">
<!-- if you don't use bootstrap.css make sure to add [position:relative] if div parent have float property.  -->
    <div class="col-sm-4">
    <!-- box you want to pin inside [id="pinBoxContainer"] have class or id -->
        <div class="pinBox">
            <h2 class="headColor">Example box</h2>
            <p>some text</p>
        </div>
    </div>

    <div class="col-sm-8">
        <h2 class="headColor">Example box</h2>
        <p>some text</p>
    </div>
</div>

3. Call the plugin

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

$(document).ready(function() {

    $(".pinBox").pinBox({
        Top : '50px',
        Container : '#pinBoxContainer',
    });

});

Call the plugin with options

$(document).ready(function() {

    $(".pinBox").pinBox({
        //default 0px
        Top : '50px',
        //default '.container' 
        Container : '#pinBoxContainer',
        //default 20 
        ZIndex : 20,
        //default '767px' if you disable pinBox in mobile or tablet
        MinWidth : '767px',
        //events if scrolled or window resized  
        Events : function(e){
            console.log(e);
            // e.current => current scroll top [number]
            // e.direction => scroll down or up [up,down]
            // e.width => window width [number]
            // e.active => if pinBox active [true,false]
            // e.disabled => if window width < MinWidth pinBox will disabled [true, false]
        }
    });

});

Reload trigger

$(document).ready(function() {

    $(".pinBox").trigger('pinBox.reload');

});

Examples

examples Here.

Changelog:

1.1.0

  • added pinBox.reload trigger
  • resolved height if the parent height changed
  • resolved position if resize or reload page and scroll top > 0

The MIT License (MIT)

Copyright (c) 2016 Mahmoud Elnezamy

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.