I have a custom timeline view like this: http://jsfiddle.net/B4xRb/1/
The inner vertical scroll affects the rows beneath the header only.
The parent horizontal scroll affects the entire timeline.
<div class="parentDiv">
<div class="monthHeader"></div>
<div class="lanes"></div>
</div>
However, how could I structure this so that the vertical scroll bar can be seen WITHOUT
adjusting the row data as it can be really wide.
initially scrolling to the right, I want it so as you load the page, both scroll bars are visible
Here's the solution I came up with, using jQuery: http://jsfiddle.net/eB8WQ/6/
First off, to hide the second outside vertical scroll bar, add this code
html, body {
overflow-y: hidden;
}
for .lanes, you want to hide the horizontal scroll bar and set the initial width to 100%.
width: 100%;
overflow-x: hidden;
Next, the javascript you want to use sets the width of .lanes to 100% while scrolling (to avoid the messy flickering problem), and when you're done scrolling, it calculates the position of the horizontal scrollbar and adds that value to the width of your body element. Use the $.data function to store the value.
More information on $.data: http://api.jquery.com/jQuery.data/
$('.parentDiv').scroll(function() {
$('.lanes').css("width", $('.monthHeader').width());
});
$('.parentDiv').scroll(function() {
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
$('.lanes').css("width", $('.parentDiv').scrollLeft() + $('body').width() + "px");
}, 100));
});
Some code taken from this previous answer.
Related
I have two 50% width columns template - with 700% and 200% of height. 200% column is sticky bottom, so I can always see it.
But if I scroll to the bottom of the page and start scroll up - right column will not be scrolling. It will start scrolling only when I get up to 200% of page top.
Is it possible to scroll right column always when it end?
For example, if I scrolled to end of page (or more than 200% height) and start to scroll up - I want to scroll to the right column too.
Example:
codepen.io
The common methods to disable scrolling in Javascript are:
Force scroll the user back to a specific spot or element
window.onscroll = () => { window.scroll(0, 0); };
Hide the overflow (no scrollbars)
document.body.style.overflow = "hidden";
Show the content in a fixed full-screen container
<div style="width: 100vw; height: 100vh; position: fixed; top: 0; left:0; z-index: 999"></div>
I have a bootstrap modal popup on my page. The popup is a bit long so html adds the vertical scroll bar which doesn't look so good with the animation effect.
So, I want to remove this scroll bar but still be able to scroll.
Any help?
It may help you. Fixing the overflow hidden will remove the scrollbar, To get full content within the page use overflow auto to modal body
CSS:
.modal{
overflow:hidden;
}
.modal-body{
overflow:auto;
}
If you are using bootstrap version 4. You can use this css code.
.modal-scrollbar-measure {
overflow: hidden !Important; }
.modal class has overflow-y: scroll rule which results in scrollbar always visible.
https://stackoverflow.com/a/18715220/9143855
that because you use overflow : scroll ;
the scroll value of overflow property add scroll ball line to both sides vertically and horizontally you should use instead overflow auto which will just add one side scroll for which it needed the most
You can also use the modal events for this:
$("#modalID").on('shown.bs.modal', function(){
/* Hide the body scrollbar. */
document.body.style.overflow = "hidden";
});
$("#modalID").on('hidden.bs.modal', function(){
/* Show the body scrollbar. */
document.body.style.overflow = "auto";
});
the events can be seen here: https://mdbootstrap.com/docs/jquery/modals/events/
as you know if html content vertical view is more than browser window, a vertical scroll bar will add to page. It will cause moving html content into left which does not have a good view.
You can avoid this treat using this CSS code:
html{
overflow: scroll;
}
But there is a problem with this code, you will always see a disabled scroll bar on right side of the page. Now let's check another way, in this way you will subtract body width of the scroll width:
body {
width: calc(100vw - 68px);
margin-left: 34px;
}
This will put body in center and if in future a vertical scroll bar add to the page, it won't affect content and will be on the right side out of the body area! This way is good but there is a very little problem. you have subtracted your body width!!! Just think I have a fully filled body area! In this situation I need the whole 100% width and also I do not want the scroll bar to move my content into left and also I do not want to see a disabled scroll bar always!
So I'm looking for a way I can make scroll bar while showing on top of html content. so Nothing will move and also I have 100% width and when ever it is needed I will see scroll bar.
Is there such trick? Hope I'm clear enough.
My website has a fixed width of 1024px to easier implement for smaller screens, the header and the footer that are displayed are in a fixed position.
However when the users has a smaller width than 1024px the header and footer are cut off, which is fine. However you cannot horizontally scroll to see the rest of them.
I imagine to fix this it'd be something to do with the CSS, however I'm unsure on what properties to change / use.
The pages are constructed like so:
<body>
<div class='header'>
<div class='headerbar'>
<div class='headerleft'><h1>BMRA Web Client</h1></div>
<div class='headerright'><!--image here--></div>
</div>
</div>
<div class='footer'>
<div class='headerbar'>
<div class='footerleft'></div><div class='footermiddle'></div><div class='footerright'></div>
</div>
</div>
</body>
That's as simple as put overflow-x: auto in your header with 100% width.
.header {
overflow: auto;
}
By this mode, you'll have a header with 100% of width, in small screens you'll see how it shrinks. With the hard pixel definition of the elements inside the header (as 1024px), your content will have this width and the overflow in the parent allows you to scroll it horizontally.
If this doesn't fits with your requirements, maybe you need a global scroll solution, that can be made with simply javascript.
EDIT
As we talk in comments, your solution will be to handle global horizontal scroll and move the fixed header with the content, like a relative or absolute header. To make this you need javascript to read how many pixels you need to move the fixed header. Here you are the complete code:
// when scroll
$(window).on('scroll', function(e) {
//calculate left position
var left = $(this).scrollLeft();
//apply to header in negative
$('.header').css('left', -left);
});
Do you like to see it working? Try this fiddle:
http://jsfiddle.net/fbvat00q/
EDIT 2
As far as you need to have the background fixed, you must to relativize the children and target it in the javascript. So your final code will be:
CSS:
.headerbar {
position: relative;
}
Javascript:
$(window).on('scroll', function(e) {
var left = $(this).scrollLeft();
$('.headerbar').css('left', -left);
});
See it working:
http://jsfiddle.net/fbvat00q/1/
If the main wrapper (that one which is set to width: 1024px) doesnt have overflow: hidden as a property, you should be able to scroll horizontally. Try to set it manually to overflow: auto
Loot At This Real Example
You can set wrapper with overflow: scroll, and fixed position, and set for inner value, or spesfic style you want
To manage abehaviour when content overflow a container(both vertical and horizontal), with fixed dimension, you can use the CSS overflow property (see this link for more details):
scoll : to scroll when content overflow
hidden : to hide the overflowed content
visble : to see the overflowed content even if it does not fit the container
In your case you have to set the property to scroll
.selector{overflow: scroll}
If you want to only manage horizontal overflow, you can set overflow-x CSS property .selector{overflow-x: scroll}
For the vertical overflow you can set overflow-y, .selector{overflow-y: scroll}
Try setting overflow to scroll horizontally. e.g:
.header {
overflow-x: scroll;
}
As here: W3C Link
I'm trying to make the main body of my site to have a fixed height (I think!).
Anyway, the site body is just white, with a border of size 1. Basically, the size of the body is determined by what's in it so, for example, it will resize automatically as more things are added.
What I want is vertical scroll bars so the body doesn't extend forever (is that right?). Should I have a fixed body size?
If you want vertical scroll bars you can use this in your CSS;
body {
height: 900px;
overflow-y: scroll;
overflow-x: hidden; /* hides the horizontal scroll bar */
}
What are you trying to accomplish? You sound unsure if you even want the scroll bars; is there a reason you want to show the scroll bars instead of just having the browser handle the scrolling when the content gets larger than the window?
Yes. You need a fixed height
body{
height: your-height;
overflow:auto;
}
will generate scroll bars only when you overflow the area without growing it vertically.
So, in your body create a layer:
<div id="mainbar">
</div>
And using CSS you can set the height:
div#mainbar {
min-height:100px;
overflow:auto;
}
The min-height guarantees the initial height that you need. Once it goes over that, it you will automatically have scrollbars. If you would rather the page itself scroll and the body lengthen, just take out the overflow line from the CSS.
If you want the vertical scroll bars to an inner div on your site (like so you can have a footer visible at all times), simple specify the height of the div:
#inner { max-height: 300px;
}
I think the default for the overflow is to scroll, but if your content is cutting cut off with no scrollbars, you could also set
overflow: auto;