Coder Social home page Coder Social logo

wecodepixels / theia-sticky-sidebar Goto Github PK

View Code? Open in Web Editor NEW
568.0 36.0 209.0 1.19 MB

Glues your website's sidebars, making them permanently visible while scrolling.

License: MIT License

JavaScript 100.00%
sidebar javascript scrolling ux website-sidebars sidebar-height

theia-sticky-sidebar's Introduction

Theia Sticky Sidebar

A JavaScript library that glues your website's sidebars (or any vertical column for that matter), making them permanently visible when scrolling up and down. Useful when a sidebar is too tall or too short compared to the rest of the content. Works with virtually any design and supports multiple sidebars.

WordPress

Theia Sticky Sidebar for WordPress

Also available as a premium WordPress plugin that comes with a user-friendly admin panel and supports a plethora of themes out-of-the-box.

Examples

3 columns example

4 columns example

Bootstrap 4 example

Foundation example

Install

Bower

If you are using Bower as your package manager:

bower install theia-sticky-sidebar

NPM

If you are using NPM as your package manager:

npm install theia-sticky-sidebar

Usage

Your website's HTML structure has to be similar to this in order to work:

<div class="wrapper">
  <div class="content">
    <div class="theiaStickySidebar">
    ...
    </div>
  </div>
  <div class="sidebar">
    <div class="theiaStickySidebar">
    ...
    </div>
  </div>
</div>

Note that the inner "theiaStickySidebar" divs are optional, but highly recommended. If you don't supply them yourself, the script will create them for you, but this can be problematic if you're using ads or iframes, since they will be moved around in the DOM and as a result will get reloaded.

Note: Make sure to use <!DOCTYPE html> in your page, otherwise you might run into weird issues.

For the above example, you can use the following JavaScript:

<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="dist/ResizeSensor.min.js"></script>
<script type="text/javascript" src="dist/theia-sticky-sidebar.min.js"></script>
		
<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery('.content, .sidebar').theiaStickySidebar({
      // Settings
      additionalMarginTop: 30
    });
  });
</script>

ResizeSensor

Theia Sticky Sidebar uses the CSS Element Queries library to detect when your sidebars change height, so that it can recalculate their positions. This can happen if you are using an accordion, for example.

You can choose not to include the ResizeSensor.min.js script in your page, in which case Theia Sticky Sidebar will continue to function (possibly even a bit smoother) but will not automatically detect height changes.

Settings

containerSelector

The sidebar's container element. If not specified, it defaults to the sidebar's parent.

additionalMarginTop

An additional top margin in pixels. Defaults to 0.

additionalMarginBottom

An additional bottom margin in pixels. Defaults to 0.

updateSidebarHeight

Updates the sidebar's height. Use this if the background isn't showing properly, for example. Defaults to true.

minWidth

The sidebar returns to normal if its width is below this value. Useful for responsive designs. Defaults to 0.

disableOnResponsiveLayouts

Try to detect responsive layouts automatically and disable the sticky functionality on smaller screens. More exactly, it detects when the container and the sidebar are moved one on top of the other, instead of showing up side-by-side. Defaults to true.

defaultPosition

The sidebar must have a non-static position, as the inner sticky-sidebar uses position: absolute. Defaults to relative.

namespace

Events are binded using a namespace, so that you may unbind them later on without affecting others. Defaults to TSS.

Credits

Stock photos courtesy of Unsplash.com

theia-sticky-sidebar's People

Contributors

alexeykuz avatar andrewchilds avatar asadkn avatar benmorel avatar liviucmg avatar luizreginaldo avatar webfella avatar wvega 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  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  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

theia-sticky-sidebar's Issues

The importance of <!DOCTYPE html>

First of all, thank you for the amazing plugin!
My sidebar was always fixed on top, scrolling down only when the content was scrolled to the end. After hours of work, I found out that this bug is caused by the DOCTYPE html declaration ausence. I suggest mencionate this on the docs.
Obs.: Sorry for the bad english. :-)

Top part of sidebar goes under header

Hello,

Thanks for the work you put into this plugin!

This works great except that a portion of the sidebar like 20% goes under the header and continues perhaps until it reaches the top. My header is about 360px so I set additionalMarginTop:360 but it didn't help, it appears that the plugin does nothing with this value?.

The whole idea of this is to keep useful items completely visible as the user scrolls up and down the right content. Please help, thanks.

Here's a screenshot of the relevant sections of my code;

screen shot 2017-01-29 at 1 36 29 am

No documentation for disableOnResponsiveLayouts which is enabled by default

Sticky was working on some mobile devices, but not on others. By trial and error I found out this had to do with the width of the viewport. After trying a ton of different configurations (none of which helped one bit), I decided to read the source code, and that is where I found this option called disableOnResponsiveLayouts. Setting it to false when initializing did the trick. You might want to document this.

Clickable elements become non clickable

When I include thea into my sidebar,the clickable contents such as check box and radio buttons wont respond to click.The body of thea takes over my elements.Basically am using it for my left side filters

1px issue at the bottom of sidebar

Hello again!

I's more like a question than an issue because I'm not quite sure if it's a bug or I just misunderstood something. I've recently found that after scrolling bottom I always get 1px difference between sidebar's and content's bottom borders. So I've checked the code and found that it happens because of padding-bottom: 1px rule that is being added to the sticky every time.

Part of the code responsible for that:

// Add a temporary padding rule to check for collapsable margins.
var collapsedTopHeight = o.stickySidebar.offset().top;
var collapsedBottomHeight = o.stickySidebar.outerHeight();
o.stickySidebar.css('padding-top', 1);
o.stickySidebar.css('padding-bottom', 1);
collapsedTopHeight -= o.stickySidebar.offset().top;
collapsedBottomHeight = o.stickySidebar.outerHeight() - collapsedBottomHeight - collapsedTopHeight;
if (collapsedTopHeight == 0) {
    o.stickySidebar.css('padding-top', 0);
    o.stickySidebarPaddingTop = 0;
}
else {
    o.stickySidebarPaddingTop = 1;
}
if (collapsedBottomHeight == 0) {
    o.stickySidebar.css('padding-bottom', 0);
    o.stickySidebarPaddingBottom = 0;
}
else {
    o.stickySidebarPaddingBottom = 1;
}

It works nice for top collapsedTopHeight but doesn't for the collapsedBottomHeight. Consider:

// calc top offset
var collapsedTopHeight = o.stickySidebar.offset().top;
// calc height with paddings
var collapsedBottomHeight = o.stickySidebar.outerHeight();
// add 2px to height
o.stickySidebar.css('padding-top', 1);
o.stickySidebar.css('padding-bottom', 1);
// collapsed top height becomes 0
collapsedTopHeight -= o.stickySidebar.offset().top;
// collapsedBottomHeight = (original_height + 2px) - original_height - 0
collapsedBottomHeight = o.stickySidebar.outerHeight() - collapsedBottomHeight - collapsedTopHeight;
// will never be true
if (collapsedBottomHeight == 0) {
    o.stickySidebar.css('padding-bottom', 0);
    o.stickySidebarPaddingBottom = 0;
}

Seems like we should add - 2 to collapsedBottomHeight calculation line if I didn't miss something.

Publish on NPM

Hello,

First of all, great work.

I'd like to use this on a project built with NPM/webpack. Is it possible to publish on NPM in addition to bower?

Thanks!

Breaking on Short Content Column

So first off, love this plugin. Thank you! I'm using it on my site, TV Fanatic. We have a 2 column layout. Content and Sidebar. Our content is set up like:

.row-fluid
  #content_wrapper
    #content
      .theiaStickySidebar
  #sidebar
    .theiaStickySidebar

With CSS:

#content_wrapper {
  margin-right: -300px;
  float:left;
  width:100%;
}
#content {
  margin-right: 320px;
}
#sidebar {
  width : 300px;
  float : left;
}

I do this so I can put my content at the top of the HTML source with the sidebar on the right without using float : right. For SEO purposes.

It seems to be working in most cases with your sticky sidebar, unless our content is super short like on this page:

http://www.tvfanatic.com/forum/gossip-girl/

Scroll to the bottom and you'll see an explosion of the left hand content into the right.

All widgets are deleted when "Pre-render the inner container for each sidebar" activate

All widgets are deleted (really deleted on the database) when we do some change on widget area.
The problem is related with "Pre-render the inner container for each sidebar", when this option are activated the plugin adds a div around the sidebars (even on admin area), and this cause the problem when adding/remove widgets if you refresh after, all widgets are gone, the drag and drop also stop working.

Add "&& ! is_admin() " in the if in "dynamic_sidebar_before" and "dynamic_sidebar_after" solves the problem.

Unstable with DFP tags

Thanks for great plugin!

It's really hard to get this error, but sometimes DFP iframe ads are removed from page after theia initialization. I have inner containers with theiaStickySidebar class, but it doesn't help.
Could you fix it or just give me an advice when I should initialize theia before or after fetching the ads?

Causes a javascript error in Gillian wordpress theme

scripts.js?ver=1.0:1062 Uncaught TypeError: $(...).theiaStickySidebar is not a function
at HTMLDocument. (scripts.js?ver=1.0:1062)
at i (jquery.js?ver=1.12.4:2)
at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2)
at Function.ready (jquery.js?ver=1.12.4:2)
at HTMLDocument.K (jquery.js?ver=1.12.4:2)


$('#sidebar').theiaStickySidebar({
additionalMarginTop: parseInt( $('.sh-header').height() + $('#wpadminbar').height() + 15 ),
minWidth: 1026
});

Fluid-Fixed Layout - With Sticky Sidebar

I have a layout, the content area is fluid, ie with 100% width, the sidebar has a fixed width of 200px. So far so good, I'm using theiaStickySidebar to keep the sidebar or the content suspended when the height of one is larger than the other, the plugin works fine, while only the content has a height higher than the sidebar, but if it is otherwise as in the example, that is, the sidebar is larger than the content, the suspension does not work. But it does not stop there, it would work just fine, but in a common layout only with float. But in that layout with fluid content and fixed sidebar, it is not working.

https://codepen.io/johnquimera/pen/bMGJXP

Top margin when content is too big

Hello!

First, thanks you for your plugin. I have tried many and yours was by far the best.
I have a question concerting the top margin of a sticky elements.

I took the example straight from your rep (3 columns), and added a lot more text content in the "Left Side bar" (I guess this is the same as the “right Sidebar”).

When that happens, the additional top margin does not work. Therefore, when I scroll, some text becomes invisible. Is is possible to make it so that the div always sticks on top (the same way when we scroll back up? the margin makes it that the div sticks to the top, without hiding any content).

Let me know if you understand.

Thank you so much in advance!

detached sidebar on Android Tablet

We have an issue with our samsung test tablet and the theia sticky sidebar. If we zoom in and out quite fast, the sidebar will detach itself form the leftern site and then it flies around on the site. It happens even with you examples, so its not in our code.
I will have a look into the theia code, but I would be very glad, if you can fix it.

See image for further explaination:

bildschirmfoto 2015-10-19 um 13 13 19

While on zoom the sidebar should stay on their original position. It should be fixed to top/bottom, but it shouldn't be left/right positioned.

Limit scroll top because there are more elements in the sidebar

I have 3 different widgets in a sidebar. The only problem with your plugin is when scrolling top again, because the sticky element overlays the rest of the elements until it gets to the top. Is there any way to limit the sticky element at the top when it touches the widget that it has on the top of it? Nice plugin by the way!

Nested theiaStickySidebar doesn't work properly

Hey Guys,

I'm using theiaStickySidebar for the main website's content and sidebar and it working great until create another sticky sidebar for sharing buttons inside the main content and it working too BUT not when the main Sidebar be greater than the content.

A Fiddle live Example

Case - 1 (Not working properly) - The main sidebar is greater than the content: The main Sidebar is 7000 pixels height [.height-sidebar] - When scrolling down the share buttons section working but when you reach the bottom of the page and go up again it disappear because of a miss calculation of position.

Case - 2 (Working) The main sidebar lower than the content: Just change the class [.height-sidebar] to [1000px] and the share buttons section will be sticky when scrolling down and up with no problem.

Thanks for your great project.

How to disable it on resize?

Is there any way to disable it? On responsive page when the screen resolution changed from wide to narrow screen the sidebar always moved to the bottom, so the sticky needs to be disabled.

Transform: none - Added to a lot of elements

Hi and thank you for your plugin!

However I am having an issue where "transform: none" is applied to a parent of a higher level and I don't understand why exactly. Here's a screenshot of what I am trying to describe. I am using an off-canvas nav and because of that the transition cannot occur. Is there a quick fix for this?

image

Thanks :)

in resizing the page, side bar goes under the main content (sometimes)

Hi!
First, thank you for your code. when i was searching, i end up with the plugin results. finally i find it just here.
About the problem, sometimes in inspect element when i change the width of the page suddenly the sidebar goes under the main content or sticks to the border of the page. totally size of side bar ruins.
ps: i use bootstrap version 4
i really need your help.

Sidebar doesn't take into account horizontal scrolling

Hello.

Not sure if it was done on purpose but anyway... If we have sticky sidebar in fixed position (for example, left column with site nav) then after reducing window width below minimum to have horizontal scrollbar we get a bug: sidebar remains on its fixed position relative to viewport while we are scrolling right. While in my opinion more desirable default behaviour is to scroll out of viewport with the other content.

I've monkey-patched my local version so that sticky behave like I want but also decided to create an issue. Luckily it's a very little fix - we just need to add - $(window).scrollLeft() to the left property to get things done (by the way it's better to cache $window object also):

if (position == 'fixed') {
    o.stickySidebar.css({
        'position': 'fixed',
        'width': o.sidebar.width(),
        'top': top,
        'left': o.sidebar.offset().left + parseInt(o.sidebar.css('padding-left')) - $(window).scrollLeft()
    });
}

It can be turned on as an option for backward compatibility.

PS. Great lib, thanks for sharing!

Recalc

Is there a way to recalc the sticky sidebar after a certain event?

destroy sticky sidebar

Hi!

I want the sticky sidebar only on a viewport size 900 and bigger. How can I remove all the theia things in the code when I resize the window after loading the sticky sidebar? It causes problems on smaller screens.

I used this code:
`
$(document).ready(function() {

	    var $window = $(window);
	    
	    function stickySidebar() {
			if ( $(window).width() >= 901 ) {
			    $(document).ready(function() {
					$('.sidebar')
						.theiaStickySidebar();
				});
		    }
	    }
	    
	    $(window).scroll(function() {
           stickySidebar();
        });
        
        $(window).resize(function() {
           stickySidebar();
        });

        $(document).ready(function() {
            stickySidebar();
        });
});

`

I have a problem

hi
I added the following code to my site
But it does not work for me
Where is the problem?

The following code index.php

`








<?php get_template_part('slider'); ?>

            </div>
          </div>
        </div>
          <div class="Awp-posts">

              <h1> <i class="fas fa-coffee"></i> آخرین مقالات  </h1>
              <hr>
              <div class="card-deck">
                <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
    <div class="card">

  <?php the_post_thumbnail( 'img-post' ); ?>
      <div class="card-body">
        <div class="Awp-card-title">

          <h2>
          <a href="<?php the_permalink(); ?>" target="_blank"><?php limiter_m($post->post_title,10); ?></a>
        </h2>
        </div>
        <div class="Awp-card-text">
              <p><?php limiter_m($post->post_excerpt,20); ?></p>
        </div>
      </div>
    </div>
  </div>
              <?php endwhile; else: ?>
              <?php endif; ?>

              </div>
              <?php Awp_number_posts_nav(); ?>

        </div>

    <div class="Awp-product">
        <h4> <i class="fas fa-graduation-cap"></i> محصولات</h4>
        <hr>

        <div class="card-deck">

          <?php
$params = array('posts_per_page' => 3, 'post_type' => 'product');
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>

<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<div class="card">

<?php the_post_thumbnail( 'img-post' ); ?>
<div class="card-body">
  <div class="Awp-card-title">

    <h2>
    <a href="<?php the_permalink(); ?>" target="_blank"><?php limiter_m($post->post_title,10); ?></a>
  </h2>
  </div>
<hr>
<div class="excerpt">
<div class="Awp-price">
<?php woocommerce_template_loop_price() ?>
</div>
<div class="Awp-students">
<?php wc_product_sold_count(); ?>
</div>

<div class="Awp-more-product">
<a href="<?php the_permalink(); ?>">اطلاعات بیشتر</a>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'No Products'); ?>
</p>
<?php endif; ?>
        </div>
        <div class="Awp-All-product">
          <a href="#">مشاهده تمامی محصولات</a>
        </div>
      </div>
      </div>
    </div>
`

The following code sidebar:

The following code scripts:

`<script>
$(document).ready(function() {
$('.cantent, .sidearea')
.theiaStickySidebar({
additionalMarginTop: 30
});
});
</script>

<script type="text/javascript" src="https://artawp.com/wp-content/themes/artawp/artawp/js/theia-sticky-sidebar.js"></script> <script type="text/javascript" src="https://artawp.com/wp-content/themes/artawp/artawp/js/ResizeSensor.js"></script> <script type="text/javascript" src="https://artawp.com/wp-content/themes/artawp/artawp/js/theia-sticky.js"></script>`

Sidebar jumping when near footer

Hi first of all thanks for this neat plugin!
I used it in a few projects. In this one it's behaving strangely. When scrolling down and it's half way or near hitting footer it's starts to jump and sometimes adding loads of white space between the sidebar and footer.

I really tried to debug this one. Everything seems fine. Check out the test url: https://www.turnyourhead360.nl/projects/theia/test.html

Who can put me in the right direction?

Realtime enable and disable

Is it possible to enable or disable this plugin at any time with JavaScript?

$(document).ready(function(){

    $('#item-id').theiaStickySidebar();

    if ('any time') {
        $('#item-id').theiaStickySidebar(false); //is this posible?
    }
    if ('any more time') {
        $('#item-id').theiaStickySidebar(true); //is this posible?
    }
});

Recalc on click event

Hi there,
i want to recalc the height of sidebar when i have a click event, the recalc is automatically on resize and scroll events, and because i have a hidden content showed when click on button and that's make a changes on sidebar height.
is there any way to recalc the when clicked on button ?
something like
$("#parent").on('click', '#mybutton', function(){ $("#mysidebar").trigger( /* recalc height */ ); } );
Thanks guys.

[Question] Vanilla JS alternative?

Hello!
Let me start by saying - great script/library! Super duper duper useful - thank you so much.
Question for you: Why the dependency on jQuery? Would a vanilla JS version be something you'd consider in the future? Plain Javascript is now on-part with jQuery in terms of features, and has the potential to even outperform - not only that, but it'd also alleviate some people having to load jQuery!

Lag on Scroll

Hi

I'm using the theia-sticky-sidebar script for fixing two sidebar on left and right of the container. the problem is, people which using old computers (PC with 3 or older age) figure out with very bad lag. specially laptop users has this problem. to get this fixed. I tried to add a timer on the scroll call function

// Initialize the sidebar's position.
o.onScroll(o);

        // Recalculate the sidebar's position on every scroll and resize.
        var timer;
        $(document).scroll(function() {
            if(timer) {
                window.clearTimeout(timer);
            }

            timer = window.setTimeout(function(o) {
                return function () {
                    o.onScroll(o);
                };
            }(o), 10);
        });

It's much better now but the side bar reach to the position with delay which make it unsuitable. Please help me to fixed this.

Problem with "Collapsible Group"

Thank you for your helpfull and well documented plugin!

There is one problem I cannot solve by my own.

When you scroll down on your "Bootstrap 4 example" and then click on "Collapsible Group Item 3", I would expect that in the end Column 2 an Column 3 should end on the same level. But they don't. On next scrolling, there is a little "Jump" in Column 3.

Update: They should not end at same level, but placed better ...

I know thats not the focus of your plugin. But if you need someone to test a beta, I would love it. :)

Tested on Firefox 51.0.1 and Chrome 56.0.2924.76.
(Click on "Collapsible Group Item 3" breaks on online-Example but works fine on my local maschine.)

Best wishes,
Zeg

Bug: Blinking in IPad Safari.

Thank you for the great lib. But looks like there is a problem when recalculating in IPad Safari.

Check the gif below to understand what I am saying, when scrolling to bottom or top the left content is blinking strangely.

insedia theia

Both sides (content and sidebar) are in the Theia initializer:

$('.categories .content, .categories .sidebar-content').theiaStickySidebar();

It's working great in another browsers and devices, but in Ipad Safari is blinking on recalculating.

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.