Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle sidebar with a click on the white space #42

Closed
hkalant opened this issue Jun 7, 2014 · 13 comments
Closed

Toggle sidebar with a click on the white space #42

hkalant opened this issue Jun 7, 2014 · 13 comments
Milestone

Comments

@hkalant
Copy link

hkalant commented Jun 7, 2014

In order to expand/hide the sidebar you need to click on the icon. How can I hide the sidebar by clicking on the white space and not necessarily on the icon?

For example: http://benplum.com/

Thanks.

@hkalant hkalant changed the title Toggle sidebar with a click in the white space Toggle sidebar with a click on the white space Jun 7, 2014
@laymonk
Copy link

laymonk commented Jun 7, 2014

On your site, you have an additional issue: with the side-bar expanded, the scroll bar vanishes, and so you cannot scroll down in the displayed post.

At first I thought this might have had something to do with your switching layout to layout-reverse. But I just tested this on my local install, and that problem is not there.

So, I reckon this is to do with the ordering of your markup or something you have introduced .. the base lanyon config is not displaying this behaviour

@laymonk
Copy link

laymonk commented Jun 7, 2014

OK, using firebug light, what I can see is that your shifter-page div has enclosed the shifter-navigation div .. I suspect this is not what you are seeking to do. Try and seperate the two divs ..

Disclaimer: I have not looked thoroughly through the rest of the setup, so I could be wide off the mark.

@hkalant
Copy link
Author

hkalant commented Jun 7, 2014

You are off topic I guess for two reasons:

  1. You are not making a suggestion on my issue (how to click on the white space and hide the sidebar)
  2. benplum.com is not my website. It is just an example I found of what I would like to do, not how I would like to do it.

For the record this is my blog: http://hkalant.github.io/

Thanks.

@laymonk
Copy link

laymonk commented Jun 8, 2014

OK .. it was not clear from your post.

was just trying to offer what I thought was useful input .. the site you
want to emulate is broken though and what you think is a feature is
probably a result of that.

On 8 June 2014 00:46, Harry Kalantzis notifications@github.com wrote:

You are off topic I guess for two reasons:

  1. You are not making a suggestion on my issue (how to click on the
    white space and hide the sidebar)
  2. benplum.com is not my website. It is just an example I found of
    what I would like to do, not how I would like to do it.

For the record this is my blog: http://hkalant.github.io/

Thanks.


Reply to this email directly or view it on GitHub
#42 (comment).

@hkalant
Copy link
Author

hkalant commented Jun 8, 2014

Let's see another more popular website: https://medium.com/
which was built by great designers and developers.

When the sidebar is expanded (click the 'M' icon), the scroll bar vanishes as well. It's hard believe this is a bug. Because when the sidebar is being expanded, it pushes the scroll bar, which is actually a part of the website, not a built-in browser addition.

Anyway, I don't really care if the scroll-bar vanishes. I just want to click anywhere on the site to hide the sidebar. That's all.

Thanks.

@laymonk
Copy link

laymonk commented Jun 8, 2014

Yeah, I have understood what you mean. The intention seems to just be to
expand the side-bar primarily to be able to make a navigation choice and
nothing else ..

If you are determined to understand how this is implemented, tools like
firebug/firebug-lite will help you quickly figure it out.

The feature that actually allows the ability to do this is a new CSS3
feature called transition, and it seems fairly straight-forward to .. the
more challenging thing is getting that to play nice with the rest of your
site's layout, and firebug can help you see how a given site is using it
(at least you get a clear view of the site structure) and can base your own
design or adjustments on that

On 8 June 2014 13:07, Harry Kalantzis notifications@github.com wrote:

Let's see another more popular website: https://medium.com/
which was built by great designers and developers.

When the sidebar is expanded (click the 'M' icon), the scroll bar vanishes
as well. It's hard believe this is a bug. Because when the sidebar is being
expanded, it pushes the scroll bar, which is actually a part of the
website, not a built-in browser addition.

Anyway, I don't really care if the scroll-bar vanishes. I just want to
click anywhere on the site to hide the sidebar. That's all.

Thanks.


Reply to this email directly or view it on GitHub
#42 (comment).

@hnrch02
Copy link
Contributor

hnrch02 commented Jun 8, 2014

If you don't care too much about mobile, you can use this snippet:

var $checkbox = $('#sidebar-checkbox');

$(document).on('click', function(e) {
  var $target = $(e.target);

  if(!$checkbox.prop('checked') ||
     $target.closest('#sidebar').length ||
     $target.is('#sidebar-checkbox, .sidebar-toggle')) return;

  $checkbox.prop('checked', false);
});

If you want this to properly work on mobile you'll need to insert a backdrop and then listen for touchstarts on that element. See for instance the implementation in Bootstrap.

@mdo
Copy link
Member

mdo commented Jun 8, 2014

Yeah, I don't know if I'll be adding anything to account for negative space clicks. This is meant to be as simple as possible, using only HTML and CSS. As such, this kind of behavior is intentional and purposefully limiting.

@mdo mdo closed this as completed Jun 8, 2014
@mdo
Copy link
Member

mdo commented Jun 8, 2014

I'd be open to adding a non-jQuery snippet of JS to the code to make this possible, if it's not too much overhead mind you.

@hkalant
Copy link
Author

hkalant commented Jun 8, 2014

that would be great. thanks.

@hnrch02
Copy link
Contributor

hnrch02 commented Jun 10, 2014

Here you go:

(function(document) {
  var toggle = document.querySelector('.sidebar-toggle');
  var sidebar = document.querySelector('#sidebar');
  var checkbox = document.querySelector('#sidebar-checkbox');

  document.addEventListener('click', function(e) {
    var target = e.target;

    if(!checkbox.checked ||
       sidebar.contains(target) ||
       (target === checkbox || target === toggle)) return;

    checkbox.checked = false;
  }, false);
})(document);

This should work everywhere, except IE < 9

(FYI: I used jQuery in my previous snippet, because I saw that @hkalant's site already uses jQuery.)

@hnrch02
Copy link
Contributor

hnrch02 commented Jun 16, 2014

@mdo Ping.

@mdo
Copy link
Member

mdo commented Jun 23, 2014

Oh snap.

@mdo mdo added this to the v2.0.0 milestone Jun 23, 2014
mdo added a commit that referenced this issue Jun 23, 2014
seon54 added a commit to seon54/seon54.github.io that referenced this issue Mar 13, 2022
seon54 added a commit to seon54/seon54.github.io that referenced this issue Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants