Please see this fiddle - http://jsfiddle.net/grimmus/vawE9/4/
<div class="refresh">
<div class="date" id="date">
As of 1/10/2013 16:44 2013 (GMT + 1)
</div>
<div class="loading"id="loading">
Loading...
</div>
</div>
In the blue box i am trying to toggle between the date and loading text. The date text can be varying width and i would like this width to stay the same when the text is hidden and the loading text is shown. The width of the date should expand to the left as far as necessary. The loading text should always be aligned left
I am having difficulty preserving the width of the box when showing the loading text. One solution i thought about was applying visibility hidden to the date text and then relatively positioning the loading text over this div with a higher z-index. It seems quite complicated and hope there is an easier solution.
Suggestions/Advice/Tips most welcome.
p.s needs to work in ie7+
Try this jsFiddle example:
jQuery
setInterval(function () {
$('#date').animate({
opacity: .01
}, 0, function () {
$('#loading').fadeIn(0).delay(2000).fadeOut(0, function () {
$('#date').animate({
opacity: 1
}, 0)
});
})
}, 4000);
CSS
body {
margin:25px;
}
.container {
background:#ccc;
height:50px;
width:100%;
}
.refresh {
background:blue;
color:#ccc;
height:20px;
float:right;
margin-right:25px;
min-width:150px;
text-align:left;
position:relative;
}
.date {
position:relative;
}
.loading {
display:none;
position:absolute;
top:0px;
}
Related
I have created a slideshow which sits inside a div element. The images are not added in the html, but through javascript and adjust their class attribute to fade In and Out.
I am trying to add buttons over the images for next and previous slide.
Problem I'm having is that the img tags are showing on screen and inside the html structure shown in the debugger, but when I examine the element the div is at the top with height 0px above the images? So the images are not sitting inside.
The reason for this is that I want to add buttons positioned relative to the containing div element (to ensure they stay on the left/ middle and right/middle of the image when the window is resized.
To clarify; I need to add the images inside the div #container so that the size/ position are relative to it. I then want to add the other images as buttons also relative to the div so that they remain in position when the screen is resized. How do I do this?
Demo
HTML
<div id="container">
<!--IMG elements created in JS go here-->
<img class="previous_button" src="symbols/PreviousArrow.png"/>
<img class="next_button" src="symbols/NextArrow.png"/>
</div>
<script src = "jsScript.js" type="text/javascript"></script>
CSS
#container {
position: relative;
z-index:1;
width:50%;
height:600px;
top:20%;
border:10px solid black;
}
#container img#main {
transition:opacity 2s;
z-index:1;
position:absolute;
top:20%;
opacity:0;
width:25%;
}
#container img#main.fadeIn {
opacity:1;
z-index:100;
}
.previous_button {
position:absolute;
margin-left:8%;
height:35px;
width:35px;
}
.previous_button:hover {
opacity:1;
}
.next_button {
position: absolute;
height:35px;
width:35px;
}
.next_button:hover {
opacity:1;
}
JAVASCRIPT
var curIndex=0;
var imgDuration=2000;
var timeout;
var images;
var links;
var container=document.getElementById("container");
function getImageAndLink(){
images=document.querySelectorAll('img[id]');
};
var imageArray=[
{link:"page1.html", src:"image1.gif", id:"main"},
{link:"page2.html", src:"image2.gif", id:"main"},
{link:"page3.html", src:"image3.gif", id:"main"}
];
function create(arr){
for (i = 0; i < arr.length; i++) {
var imgEl = document.createElement("img");
imgEl.src=arr[i].src;
var id=arr[i].id;
imgEl.setAttribute("id",id);
var imgElA = document.createElement("a");
var link=arr[i].link;
imgElA.setAttribute("href", link);
imgElA.setAttribute("id",id);
imgElA.appendChild(imgEl);
container.appendChild(imgElA);
}
};
function slideshow() {
images.item(curIndex).className="fadeIn";
links.item(curIndex).className="fadeIn";
var interval=setInterval(function(){
images.item(curIndex).className="";
curIndex++;
if (curIndex==images.length) {
curIndex=0;
};
images.item(curIndex).className="fadeIn";
},imgDuration);
function stopSlide(){
clearInterval(interval)
};
container.addEventListener('mouseover', stopSlide, false);
container.addEventListener('mouseout', slideshow, false);
};
create(imageArray);
getImageAndLink();
slideshow();
Looks like your issue is that the inner content of the DIV has Absolute position and then they come out of the DIV on the dom, so makes it to have the 0 height.
with taking out the absolut position of those seem to have the height (added a border to the div so that you can see):
took out the position of these like this:
.previous_button {
margin-left:8%;
height:35px;
width:35px;
}
https://jsfiddle.net/gqjcpa0m/3/
I'm trying to set up a page with a fixed header that varies in size when the browser window changes (let's say from a pc to a mobile phone). So far I got it to work fine, but now I have content I want to place underneath it and I don't want to set it on a fixed margin (because then the header will cover the top of the content when it jumps into two lines).
Is there a way to do this using html/css?
Another way to do this would probably be to set up a placeholding element, but same problem as before, how do you resize it according to the header size?
here's my code
.header{
position:fixed;
width:70%;
margin-left:15%;
margin-right:15%;
height:3em;
text-align:center;
}
/* logo positioning */
#logo{
display:inline-block;
}
/* napis na headerju */
#headersign{
display:inline-block;
vertical-align:top;
font-weight:bold;
font-size:160%;
}
/* top menubar */
#topmenu {
background-color:#009933;
color:#ffffff;
font-family:verdana;
width:100%;
height:100%;
}
/* text menubar */
.menutext {
font-family:verdana;
color:#ffffff;
}
.menutext:hover {
color:#cccccc;
}
/* text position menubar */
#linkijs{
float:left;
display:inline;
margin-left:1%;
}
#linkeng{
float:right;
display:inline;
margin-right:1%;
}
/* podatki o knjižnici */
#leftpanel {
/*positioning*/
top:0;
margin-left:15%;
background-color:#00cc66;
}
<body>
<div class="header">
<img id="logo" src="images/ijs_logo.gif" alt="logo" />
<p id="headersign">ZNANSTVENO INFORMACIJSKI CENTER</p>
<div id="topmenu">
<p class="menutext" id="linkijs">IJS</p>
<p class ="menutext" id="linkeng">ENGLISH</p>
</div>
</div>
<div id="leftpanel">
<p>
Institut Jožef Štefan <br />Knjižnica <br/>Jamova 39 <br/>1000 Ljubljana <br/><br/>tel: +386 1 47 73 304 <br/>fax: +386 1 47 73 152 <br/><br/>Delovni čas:<br/>pon-čet: 8:00-17:30<br/>pet: 8:00-17:00
</p>
</div>
<div id="rightpanel">
</div>
</body>
hope I didn't miss a similar post, been trying hard to find a solution whole morning
You can simply use an "hidden" div that initially stay under your header (so with a lower z-index), and with the same dimension:
.headerMargin{
position:initial;
width:70%;
margin-left:15%;
margin-right:15%;
height:3em;
text-align:center;
}
As Syed has mentioned in the comments this would be simple with jQuery (and is, I think, not possible with CSS to your exact specifications):
$(function(){
$('.body-element').each(function(){
var headerHeight=$('.variable-size-header').height();
// headerHeight+=15; // maybe add an offset too?
$(this).css('margin-top',headerHeight+'px');
});
});
I've named the element classes as a description because I wasn't 100% certain which of your elements you wanted positioned and which needed the margin; drop that in a comment and I can edit my answer.
Please see my fiddle. In this fiddle, the black box is fixed on page. If we scroll the page the black box is overlap the map also. I want to stop the fixed position before the map. If we scorll the page after the map, black box should stay before the map. How can I do?
CSS:
.item{ background:#eee; padding:10px; width:50%; margin-bottom:15px;}
.new_icon{ position:fixed; width:100px; height:100px; background:#000; right:10px;}
http://jsfiddle.net/6f8HK/
No need for javascript, add an id to your iframe, set the css to:
#map
{
position:relative;
z-index:2;
}
And give your fixed element a lower z-index:
.new_icon {
position:fixed;
width:100px;
height:100px;
background:#000;
right:10px;
z-index:1;
}
Js fiddle
Add z-index: -1; to .new_icon
DEMO
Try this Working Fiddle.
JQUERY:
$(window).scroll(function() {
if ($(this).scrollTop() > 450)
{
$('.new_icon').fadeOut();
}
else
{
$('.new_icon').fadeIn();
}
});
NOTE : use can use .show/.hide if you don't like the fadein/fadeout effect.
I am putting show more alert button. button display type relative show it actual space if i move above using right/top/bottom/left
How can I remove relative button space actual place space without set height of parent.
check fiddle for based.
HTML
<div class="alert-list">
<div class="alert-error">Plase update your system with new release</div>
<div class="alert-notify">New Release are ready for download verify with hash</div>
<div class="alert-error">System is not actived. Please activce first for full access</div>
<div class="alert-error">System is not actived. Please activce first for full access</div>
<button class="bnt-show-alerts">show more</button>
</div>
CSS
.alert-list {
width:400px;
background-color:#E9E9E9;
padding:3px;
/*height: auto; automaticly arrange*/
}
.alert-error {
background-color:rgba(255, 0, 0, 0.2);
margin:2px;
}
.alert-notify {
background-color:rgba(0, 255, 0, 0.2);
margin:2px;
}
.bnt-show-alerts {
position:relative;
right:-310px;
bottom:30px;
opacity:0.5;
}
.bnt-show-alerts:hover {
opacity:1.0;
}
When you use relative position using right/top/bottom/left the the button is moved from its static position leaving its actual space empty. If you want to move the button from its actual space without the empty space of the element use absolute positioning to place the element. Read more about positioning here
Fiddle
CSS changes
.alert-list {
position:relative;
}
.bnt-show-alerts {
position:absolute;
right:0;
bottom:5px;
opacity:0.5;
}
Can someone explain how to code the feedback button seen on foursquare.com? It's a vertical button on the side of the webpage and it opens a new window and dims out the background. I've seen this on some other sites as well. Thanks in advance.
How they did it...
The button is provided through the http://getsatisfaction.com service. This service is similar to other services like http://sharethis.com which exist to minimize the programming required to create a fully-rounded website. Essentially you setup an account (I'm assuming...) and they provide you with a javascript code-block that you include in your projects, which causes the vertical-button to appear on your site.
Do it yourself...
This wouldn't be that difficult the do yourself. I quickly worked up a jQuery example. Suppose we have the following markup:
<div id="feedback">
<p>Here is where you would have your form.</p>
<div class="toggler">?</div>
</div>
.toggler will be our button in this case. We'll want to place it outside of the feedback box with some css, and also place the feedback box with some css too:
#feedback { position:absolute; left:0; width:200px; padding:10px;
background:red; color:white; }
.toggler { width:25px; height:50%; color:white; background:blue;
text-align:center; position:absolute; top:25%;
right:-25px; cursor:pointer }
This could be cleaned up a bit. But now that we have our elements, we can add some toggle-logic with jQuery:
$(function(){
// When the user clicks on .toggler
$(".toggler").click(function(e){
// Get a reference to our feedback box
var feedback = $("#feedback");
// If it's in the process of being opened (or is opened)
if ( $(feedback).hasClass("opened") ) {
// Close it
$(feedback)
.removeClass("opened")
.animate({"left":0}, 1000);
} else {
// Else, Open it
$(feedback)
.addClass("opened")
.animate({"left":-$(feedback).outerWidth()}, 1000);
}
});
});
Online demo: http://jsbin.com/iyenu4
Have a look at jquery and the jquery UI javascript library for implementing those kinds of interavtive features.
Here is an example: http://wpaoli.building58.com/2009/08/jquery-animated-feedback-tab-thingy/
Looks like they're using the Lift modal dialog for the popup and background dimming.
The button is probably positioned using CSS fixed positioning. Fixed positioning means that it remains in the same place on the screen, not on the page. This allows it to 'float" over the text even when you scroll.
The popup dialogue is the same. Clicking on the button toggles the display CSS property between none and something other than none, probably block.
The gray background, I'd guess is created with a big fixed position <div> with width:100% and height:100% and some opacity.
Try this:
HTML
Save this as example.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>Example</title>
<link rel="stylesheet" href="example.css" type="text/css" />
<script type="text/javascript" src="example.js"></script>
</head>
<body>
<h1>Example</h1>
<a id="clickhere">Click here for the popup!</a>
<div id="main">
<p>
Lorem ipsum dolor sit amet
</p>
</div>
<form id="popup" class="dialog" action="#">
<div id="popupbackground"></div>
<div class="dialog">
<h2>Popup!</h2>
<a id="closepopup">Click here to close this dialog</a>
</div>
</form>
</body>
</html>
CSS
Save this as example.css:
html {
height:100%;
}
body {
height:100%;
}
form.dialog {
height:100%;
width:100%;
position:fixed;
top:0px;
left:0px;
text-align:center;
padding-top:10%;
display:none;
}
form.dialog div.dialog {
width:400px;
background-color:gray;
margin:auto;
text-align:left;
border:2px solid black;
padding:10px;
position:relative;
z-index:10;
}
form.dialog label {
display:block;
}
form.dialog input {
width:99%;
}
form.dialog textarea {
width:99%;
height:200px;
}
a {
cursor:pointer;
text-decoration:underline;
font-weight:bold;
}
#popup #popupbackground {
background:gray;
opacity:0.4;
filter:alpha(opacity=40);
position:absolute;
top:0px;
left:0px;
height:100%;
width:100%;
}
JavaScript
Save this as example.js:
window.onload = function() {
document.getElementById("clickhere").onclick = function() {
document.getElementById("popup").style.display = "block";
};
document.getElementById("closepopup").onclick = function() {
document.getElementById("popup").style.display = "none";
};
};
The idea is that the <form> consumes the whole screen, because of the width
and height properties in the form.dialog rule. Since that rule also specifies a fixed position, the user can never scroll away from the contents of this <form>. We can then center the <div class="dialog"> using a margin:auto, so it floats, centered on the page. The <div id="popupbackground"></div> provides a faded gray backdrop.