How to resize a real time flot chart? - javascript

Is there a js library or a way to resize my real time flot chart when I resize the browser? My chart is like this example. The difference between the example and my chart is that it is put in a table.
EDIT:
I have found that jquery.flot.resize.js exists and does what I want. But does influence the library functionality the position of the flot in the table?

You can use relative units to resize element relative to window size one of them is %. Set width and height of element in % it will resize this element according to %age size of parent. Example
Resize window to see results!
<div style="
position: absolute;
width: 50%;
height: 50%;
background: red;">
Resizeable DIV
</div>
Demonstration given here https://jsfiddle.net/7rtguhuv/

I post the solution to my problem here. Maybe someone will need it.
I used jquery.flot.resize.js and the next code:
<table cellpadding="0" cellspacing="0" class="floatedTable">
<tr>
<td class="auto-style15">
<div id="content">
<div class="demo-container" style="position:absolute; width:75%; height:80%; top: 57px; left: 64px;">
<div id="placeholder" class="demo-placeholder" style="position:absolute; width:95%; height:95%; top: 17px; left: 24px;"></div>
</div>
</div>
</td>
</tr>
</table>
where class="floatedTable" is:
.floatedTable {
width: 100%;
height:100%;
}

Related

bigvideo.js - stack DIVs over and under bigvideo container

So I've started playing around with bigvideo.js (which is built on top of video.js) and it works fine for the basic usage of having a fixed background video over the whole screen. I have also managed to show it inside of a div.
My problem though, is that I can't seem to stack other DIVs with other content over or under the bigvideo.js container div, and I can't seem to figure out how to solve this.
My HTML:
<div style="float: left; width: 100%; height: 300px;">
<h1>hi there</h1>
</div>
<div style="float: left; width: 100%; height: 500px;" id="intro-video-container">
</div>
JS firing up bigvideo:
$(function() {
var BV = new $.BigVideo({container: $('#intro-video-container'),useFlashForFirefox:false});
BV.init();
BV.show('intro.mp4',{ambient:true});
});
So the video container div ALWAYS gets stuck up to the left top of the body, no matter if I try to force it down with margin-top, or place divs before it, etc.
Any ideas?
Update, here is an illustration of what I kind of what to achieve:
Try to use container div (so called wrapping) in your page where you will place the desired content (as on the plugin's example page):
CSS
.box {
background:#444; background:rgba(0,0,0,.6);
padding:20px;
border-radius:5px;
margin-bottom:20px;
}
.main {
position:relative;
margin:50px 50px 440px 220px;
min-width:300px;
-webkit-transition-duration:0.6s;-moz-transition-duration:0.6s;-ms-transition-duration:0.6s;-o-transition-duration:0.6s;transition-duration:0.6s;
}
.dimmed {
color: #ccc;
}
#big-video-wrap {
height: 100%;
left: 0;
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
}
HTML
<div id="big-video-wrap"></div>
<div class="main">
<div id="overview" class="box">
<h1>BigVideo<span class="dimmed"><small>.</small>js</span></h1>
<h2>Simple Ambient Video Example</h2>
</div>
</div>
JavaScript
$(function() {
var BV = new $.BigVideo({container: $('#big-video-wrap'),useFlashForFirefox:false});
BV.init();
BV.show('intro.mp4',{ambient:true});
});
EDIT:
Now, it is more clear what you are trying to achieve, the simplest solution is to include an iframe on place of the div, which points to your full-screen video page.
I.e. create page video.html with all initializations and plug-in includes, then use it as source of your iframe on main page. Your iframe can be styled to match the desired dimensions (for example 100% width and 300px height).

How to position a div on the bottom of a parent td?

I need to place a <div> with fixed height (100px) and full width (100% of the parent <td>) within a <td> on the bottom. The <td> could be higher than the browsers viewport height as the content of the other <td>s are probably huge.
I already tried some solutions like this (link), which is actually placing the div at the bottom of the browsers viewport.
Edit:
Here's a snippet of what is NOT working (according to the link above):
td {
position: relative;
}
div {
position: absolute;
bottom: 0;
}
Is there any option to fix a <div> to the total bottom of a <td> using PHP, HTML, CSS or JavaScript (jQuery also)?
Edit 3:
Another problem occuring, when I use the solution as showed above is, that if I assign the div the property "position: absolute;" the "width: 100%;" relates to the viewport width, not the td width.
Edit 4:
The actual code of my page:
html:
<tr>
<td id="content">
</td>
<td class="sidebar">
<div class="internal">Notice</div>
</td>
</tr>
css:
#content{
height: 1000px;
}
.sidebar{
width: 10%;
min-width: 200px;
position: relative;
}
div.internal{
position: absolute;
bottom:0;
width:100%;
height: 100px;
}
jsFiddle: Source
Here's a working example
Use this to place the div at the bottom
td{
position: absolute;
}
div{
position: absolute;
bottom: 0px;
}
UPDATE
This is an example with your code working link
It work's for me in Chrome and IE. The Red section is your div. Is this the layout you want?
UPDATE 2
If you want to use a table layout you can try doing that: table layout
UPDATE 3: working only with tables
If the previous solution didn't work for you I'm guessing your code isn't modular enough. If you want to use tables, you might want to use only tables. Add another table inside the requested cell like this: table inside the cell . As much as I'm against it, I still think it's better than using JS to solve your problem. It will be easier to maintain in the future.
You need using something like:
<table>
<tr>
<td class="sidebar">
<div class="internal">Notice</div>
</td>
</tr>
</table>
CSS:
.sidebar{
width: 10%;
min-width: 200px;
height: 1000px;
background-color: green;
}
div.internal{
position: absolute;
height: 100px;
background-color: yellow;
}
Javascript:
$(document).ready(function () {
var $div = $('div.internal');
var $td = $div.closest('td');
$div.width($td.width() + 2);
$div.css('top', ($td.height() - $div.height() + 12) + 'px');
});
http://jsfiddle.net/Z58ZW/5/
try adding
div.myClass{
position: absolute;
bottom:0;
width:100%;
}
to the div.
Example with the div positioned only on td bottom.
JSFiddle

centering a div even if the contents is wider than the screen

This is similar to other questions asked, but with one extra issue and I can't find anyone with the same problem as me.
I have an image which is 1400px wide and which I want to be centred in the middle of the page even if the user is looking through a browser with a 800px resolution.
I can't use a BackGround image because I need to rotate this image with a few others using the jquery cycle plugin.
The way I found to centre an image by using:
div.slideshowWrap {
position: relative;
width: 100%;
overflow: hidden;
}
div.slideshowWrap div.homeslideshow {
position: relative;
width: 10000px;
left: 50%;
margin: 0 0 0 -5000px;
text-align: center;
}
<div class="slideshowWrap">
<div class="homeslideshow">
<?php echo $this->Html->image('background_01.jpg');?>
</div>
</div>
works, but when I add the extra slides required for the jquery cycle it messes up the positioning...
<div class="slideshowWrap">
<div class="homeslideshow">
<?php echo $this->Html->image('background_01.jpg');?>
</div>
<div class="homeslideshow">
<?php echo $this->Html->image('background_02.jpg');?>
</div>
<div class="homeslideshow">
<?php echo $this->Html->image('background_03.jpg');?>
</div>
</div>
I'm not sure what's the best way to sort this out? There doesn't seem to be a way to centre images, only backgrounds. But there's no way to fade in and out backgrounds like the jquery cycle plugin allows.
Anyone any ideas?
Try this:
.homeslidshow {
position: relative; /* if there is no position applied already */
}
.homeslideshow > img{
position: absolute;
left: 0px;
right: 0px;
/* and your width here */
}
I had seen this technique in a recent post.

Center div inside 100% width container with dynamic width left and right floats

I want to have 3 divs aligned inside a container div, like this:
[[LEFT] [CENTER] [RIGHT]]
Container div is 100% wide (no fixed width), and center div should remain in center after resizing the container.
Left and Right DIV have no fixed width and need to expand/contract with the container. Center DIV does have a fixed width.
I have this:
<div style="width: 100%">
<div style="float: left; height: 50px;"></div>
<div style="float: right; height: 50px;"></div>
<div style="margin: 0 auto; height: 50px; width: 500px;"></div>
</div>
Problem is, the left and right do not show because there is no set width
Any suggestions?
You can't do that with pure CSS. You need to use JavaScript. In the example below Middle div is fixed at 400px while remaining space is be split between left and right divs. With jQuery you can do
function calc() {
var ww = $(window).width();
var rem = ww - $('.div2').width();
$('.div1, .div3').css('width', rem / 2);
}
calc();
$(window).resize(calc);
Check working example at http://jsfiddle.net/M5Ghx/3/
Another option, if you wanted to avoid using javascript, would be to give the center div an absolute position and create two divs to use as buffers within the left and right divs:
<div style="width: 100%; text-align:center">
<div style="width:50%; height: 50px; float:left">
<div style="width:250px; height: 50px; float:right"></div>
</div>
<div style="margin-right:auto; margin-left:auto; position:absolute; left:0; right:0; width: 500px;height:50px;"></div>
<div style="width:50%; height: 50px; float:right">
<div style="width:250px; height: 50px; float:left"></div>
</div>
</div>
If you only care about Mozilla and WebKit, then you should look in to using the Flexible Box Model:
http://hacks.mozilla.org/2010/04/the-css-3-flexible-box-model/
That will solve all your centering issues in pure CSS. Just be sure to read the docs and play around with the different options so that you understand how it works.

Center an Image vertically and horizontally using CSS

How do I vertically and horizontally center an image when I do not know the size of it? I asked this question and someone suggested using a table. This isn't the first time I heard a table can do it but I tried without luck.
Searching SO only got me results when I do know the size of the image. How do I do this with a table?
NOTE: JavaScript/jQuery is not preferred but if there's a solution with it I'm open to it.
Pretty easy, this is the format of all my images/containers:
<div class="photo"><img /></div>
<style type="text/css">
div.photo { height: 100px; line-height: 100px;text-align:center; }
div.photo img { vertical-align:middle;}
</style>
The CSS Method
You can set an explicit height and line-height on your container to center an image:
<div id="container">
<img src="http://placekitten.com/200/200" />
</div>
<style>
#container { height: 600px; line-height: 600px; text-align: center }
#container img { vertical-align: middle }
</style>
See it in action: http://jsfiddle.net/jonathansampson/qN3nm/
The HTML/Table Method
The table method follows. It's merely utilizing the valign (vertical-align) property:
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<img src="someHeight.jpg" />
</td>
</tr>
</tbody>
</table>
A jQuery Plugin
Since you tagged this question "jQuery," I'll provide a reference to the jQuery Center Plugin that also achieves vertical/horizontal centering by using CSS positioning and dynamic reading of an elements dimensions: http://plugins.jquery.com/project/elementcenter
With a table:
<table height="400">
<tbody>
<tr>
<td valign="middle"><img /></td>
</tr>
</tbody>
</table>
The 400 is just something I picked. You will need to define a height on table so it is taller than your image.
A jquery solution would be good if you wanted to try and use divs and junk, but if you don't care you don't care. You also have to rely on JS being turned on.
HTML:
<div id="imgContainer" style="position:relative;">
<img style="position:absolute;" />
</div>
JS:
$('#imgContainer > img').each(function(){
//get img dimensions
var h = $(this).height();
var w = $(this).width();
//get div dimensions
var div_h =$('#imgContainer').height();
var div_w =$('#imgContainer').width();
//set img position
this.style.top = Math.round((div_h - h) / 2) + 'px';
this.style.left = '50%';
this.style.marginLeft = Math.round(w/2) + 'px';
});
DON'T USE TABLES. Terrible practice unless your using tabular data.
The best way to do this is with the following code.
<html>
<head>
<title></title>
<style media="screen">
.centered {
position: absolute;
top: 50%;
left: 50%;
margin: -50px 0 0 -50px;*/
}
</style>
</head>
<body>
<img class="centered" src="" width="100" height="100" alt="Centered Image"/>
</body>
This will work as long as it is not inside any elements without static positioning. All containing elements must be static positioning which is the default anyway.
Using CSS there is no easy way to vertically align an image center. Though to align it center horizontally you can use the following
<img src="randomimage.jpg" style="margin: 0px auto;" />
I would not reccommend a table for laying out an image as it is not really good practice anymore. Tables should only be used for tabular data.
There is some bad way to do it. Just display this image as block with absolute positioning (parent element must have "position: relative"). So you can play with margin-left and margin-top with negative values ~= a half of image sizes (respectively width and height)
If you don't mind losing IE compatibility (IE7 and older don't support this at all), you can use some CSS to simulate tables, without ever using one:
<div style="display: table; height: 500px; width: 500px;">
<img src="pic.jpg" style="display: table-cell; vertical-align:middle; margin: 0 auto; text-align: center">
</div>
Just pick appropriate height/width for the containing <div>.
If you don't mind losing the img-tag, you can use background-image to center an image in a container block.
markup:
<div class="imagebox" style="background-image: url(theimage.png);"></div>
style:
.imagebox
{
width: 500px;
height: 500px;
border: solid 1px black;
background-repeat: no-repeat;
background-position: 50% 50%;
}
Basically, you should be able to create a table in HTML, and the styling for the td tag should set the text-align attribute to center and the vertical-align attribute to middle. And, you can mess with other attributes, like borders, padding, etc...
I end up doing the below. Tested with firefox, chrome, IE8 and opera. All good.
table.NAME
{
background: green; //test color
text-align: center;
vertical-align:middle;
}
table.NAME tr td
{
width: 150px;
height: 150px;
}
html
<table class="NAME"><tr>
<td><img src="dfgdfgfdgf.gif" alt="dfgdfgfdgf.gif"/></td>
<td><img src="dfgdfgfdgf.gif" alt="dfgdfgfdgf.gif"/></td>
...

Categories

Resources