Jquery how to get top leftcorner of page? - asp.net

I would like to mask a asp page by a div, this one have to completly cover the page.
I can get the size of page and resize the div with this values:
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
It is ok bue the mask is contained in a div in the page.. So the mask set his position from the top left of.. the div!
How can I set the position to the top left of the whole page? thanks a lot for any ideas..

Set the mask CSS to:
#mask
{
position: fixed;
top:0; left:0;
width:100%; height:100%;
background: red;
}
It is going to start at the point 0 and cover the whole page, regardless of the scroll due the position: fixed
Example on jsFiddle

<div class="maskPage">
<div>
Css
.maskPage
{
top:0;
left:0;
width:100%;
height:100%;
background: #ccc;
position: fixed;
}

Related

How to change the reference point of an html element?

I have an iframe that has a dynamic size and needs to stay in the bottom right of the screen. There are multiple elements in play such as window size and and a min-width, but ALL of my problems would be solved if I could reference my iframe from the bottom right rather than the bottom left.
So, is there a way to treat the iframe in a way that I could say something like:
iframe {
right: 0;
bottom: 0;
}
in css and have it stuck in the bottom right corner, even when the size of the frame changes?
You need to set
iframe {
position:fixed;
bottom:0;
right:0;
}
It sounds like you need to set the position of your iframe to fixed:
iframe{
bottom:0;
position:fixed;
right:0;
}
Yes, you can apply position:fixed to the iframe and have stuck to the bottom right hand corner like so:
iframe {
position: fixed;
right: 0;
bottom: 0;
}
https://jsfiddle.net/baav59vh/

CSS - Position footer relative to body's bottom

I might me using the terms absolute and relative wrong, but hopefully you get what I mean. I want to give my footer some "bottom: 10px" so that it stays at the bottom of the page, no matter if the page's content is more or less than 100% of the browser window. I tried positioning it absolute but it will be positioned relative to the browser window then, not the body.
This is an example: http://public-demo.webflow.com
Any ideas? Thank you :)
add this to the body
position: relative
and add this to the footer
position: absolute
This way the footer will be positioned accordingly to the body
It would be good if you set the bottom to 0px.
If you want to fix this kind of problem, you can inspect your element with Mozilla, and play your code there.
FOOTER TO STICK BOTTOM IF CONTENT IS SMALLER THAN THE VIEWPORT and BEHAVE NORMAL IN OTHER CASE
You'll need a tiny JS for that.
$(function () {
var bht = $('body').height();
var wht = $(window).height();
if (bht < wht) {
$('#footer').css("position", "absolute");
$('#footer').css("bottom", "10px");
}
});
Check this fiddle - http://jsfiddle.net/3N4L9/4/
FOOTER TO STICK TO BOTTOM IN ANY CASE
This will generate same output as required :
Like page 1 : http://jsfiddle.net/3N4L9/1/
Like page 2 : http://jsfiddle.net/3N4L9/2/
It'll keep footer on the bottom of page irrespective of content and scroll.
.fixedFooter{
width:100%;
position:fixed;
bottom:10px;
}
That should work
.footer-text {
background-color: rgba(0, 0, 0, 0.49);
bottom: 10px;
color: white;
left: 0;
margin-top: 10px;
position: absolute;
right: 0;
text-align: center;
z-index: 999;
}

Have a fixed DIV element with re-sizing constraints

I have a website with the following basic layout. Essentially, I have the NAV div and SIDEBAR div at fixed positions. This is because when a user scrolls down on my page, only the MIDDLE COLUMN div will move.
The problem I have is that when the window gets shrunk horizontally, the SIDEBAR moves to left and eventually overlaps my MIDDLE COLUMN.
I have the body set to a min-width but it only affects the SIDEBAR if it is position:absolute and not position:fixed
Is there a way to keep my same method of scrolling, but have the SIDEBAR div stop moving left after a certain pixel constraint?
Thanks!
EDIT MARKUP:
div.MASTER {
position: inherit;
width:100%;
height:auto;
}
div.NAV {
position:fixed;
top:0;
left:0;
width:200px;
}
div.CONTENT {
float: left;
position: relative;
width:100%;
}
div.MIDDLECOLUMN {
float:left;
width:100%;
height:100%;
text-align:center;
}
div.SIDEBAR {
position:fixed;
top: 0;
right: 0;
width:200px;
}
Ah I see the issue. You need to assign a min width on the main container. Set the min-width to the width of the element right before it breaks.
Add a margin-left equal to the width of the nav bar to the content div.
You can use the scroll function in jquery:
$(document).ready(function()
{
var $left= $('#yourdiv').offset().left + 20; //+20 is optional
$(window).scroll(function()
{
if ($(window).scrollLeft()>$left)
{
$('#yourdiv').addClass('floater');
$('#yourdiv').removeClass('floated')
}
else
{
$('#yourdiv').removeClass('floater');
$('#yourdiv').addClass('floated')
}
});
});
where floater class is with posit absolute and floated is with position fixed.
EDIT 1:
Maybe you can use all percentage width even in the NAV bar like:
.nav{width:20%; position:fixed;}
.master{width:60%; position:absolute;margin-left:21%; }

How to use css to put an item just above the top of the screen?

I'm working on a page that animates slides out of the screen. This is how I currently do it.
var previousOffset = ($(window).height())*-1;
previousOffset = previousOffset+'px'
$('.current').animate({
top: previousOffset,
}, 500, function(){...}
I was wondering, is there a cleaner way to do it, with pure css, without measuring the height of the of the screen. Currently, the item has position:absolute, but that is not a requierment.
To be clear currently the css of .current is:
.current{
top: -"height of screen";
position: absolute;
}
I would like to do it without "height of screen".
This may depend heavily on your other markup, but you could try setting the height of the .current element to 100% and just deal with percentages. This will implicitly handle the resizing of the window for you.
Note that you must set the html & body element to 100% for this to work.
CSS
html, body {
margin:0;
height:100%;
}
.current {
position:absolute;
height:100%;
width:100%;
}
JS
$('#nextButton').click(function(){
$('.current').animate({
top: '-100%'
}, 500, function(){
// do something
});
});
DEMO
http://jsfiddle.net/GoranMottram/BQdtm/
Specify the position as fixed then set top to the appropriate negative value.
.current{
position: fixed;
height: 10px;
top: -10px; /* This will need adjusted */
}
Working Example: http://jsfiddle.net/UH4p7/

Floating div using css

i need this kind of effect in my project. there is a left corner floating red color strip. but i want to implement it for image using css. Please refer below image
http://www.w3.org/TR/xhtml2/mod-tables.html#sec_26.6.1.
you can use position:fixed; for a div.
Example code
css
#redBar {width:40px; height:200px; position:fixed; background:red;}
html
<div id="redBar"></div>
Demo http://jsbin.com/aqofa5
You can modify the background property to add your custom background image like background:url("the-path-for-the-image").
It is called fixed position. Here is css that accomplishes this:
.element { position:fixed; top:2%; right:2%;}
More info.
You can use a positioned div:
#myImgDiv
{
position: fixed;
top: 0;
left: 0;
background-image: url(path/to-img.png);
}
If it's an image related to content, it's best to use an <img> tag with an alt attribute within this div.
Let's say this is you DIV
<div id="alwaysThere"><img src="..."></div>
This should be CSS style:
#alwaysThere
{
position: fixed; /* or absolute if you want it to be fixed page top-left */
top: 0;
left: 0;
}
Use fixed position when you want your image to stay there regardless of page scrolling and absolute when you want it to stay top left on your page which means it will scroll when you'll scroll the page down.
The example you provided with a link uses fixed hence it stays there regardless of scrolling.
Pretty easy to be done, do the following:
div#divID
{
position:fixed;
top:0px;
left:0px;
}
This will give you the effect that this div will never leave the visible area of the browser.
Other position values are:
Static -- default
Absolute -- absolute in terms of the page, not the browser window
Relative -- relative to what it would be if the position was static
This is already an image. It doesn't use a floating div.
This CSS is used for the body:
background-image: url(http://www.w3.org/StyleSheets/TR/logo-ED);
background: white;
background-position: top left;
background-attachment: fixed;
background-repeat: no-repeat;

Resources