Center an image while keeping full screen height - image

I want an image to remain the full height of the browser window even if the window is made smaller. This seems to do the trick. However, at current, the image remains anchored to the left side of the screen with the right side of the image being what is lost as the window resizes. Instead, I'd like the image to chop from both sides leaving a centered image. Is this possible?
Note: I need the image in a div, not set as background.
Thanks!
Here is the CSS I'm currently using:
.div
{
min-height:100%;
min-width:100%;
text-align:center;
overflow: hidden;
margin: 0 auto;
}
.img
{
min-height:100%;
min-width:100%;
margin: 0 auto;
}

something like this ?
var origWidth;
$(document).ready(function() {
origWidth = $(window).width(); //store the window's width when the document loads
origHeight = $(window).height(); //store the window's width when the document loads
});
$(window).resize(function() {
var curWidth = $(window).width(); //store the window's current width
var curHeight = $(window).width(); //store the window's current height
var deltaTop = (curWidth- origWidth);
var deltaLeft = (curHeight- origHeight);
$("#image1").offset({top:($("#image1").offset().top + deltaTop)});
$("#image1").offset({left:($("#image1").offset().top + deltaLeft)});
origWidth = curWidth;
origHeight =curHeight;
});
JsFiddle
(inspired by this question's solution: link)

Related

empty space when dragging it

I have a simple custom splitter that works great. However, I have a little issue:
The first time I drag the splitter down it adds an empty space, after that I can drag with it with no problem (up or down). Can anyone tell me what may be causing the extra space issue? Thanks a lot in advance!
Here's the code:
PLUNKER
#HostListener('document:mousemove', ['$event'])
onMouseMove(event: MouseEvent) {
if (!this.grabber) {
return;
}
this.resizer(event.clientY - this.oldY);
this.oldY = event.clientY;
}
First, you should consider using clientHeight instead of offsetHeight because CSS height is calculated as clientHeight minus CSS paddings* while offsetHeight also includes borders height
clientHeight = content height + paddings
offsetHeight = clientHeight + borders height
Now you have two options
1) Use clientHeight together with box-sizing: border-box; (paddings will be included in css height)
ts
ngOnInit() {
this.height = parseInt(this.el.nativeElement.parentNode.clientHeight);
}
css
.textarea {
box-sizing: border-box;
}
Example
2) Use content height
ngOnInit() {
const elem = this.el.nativeElement.parentNode;
const computedStyle = getComputedStyle(elem);
const paddingsHeight = parseFloat(computedStyle.paddingTop)
+ parseFloat(computedStyle.paddingBottom)
this.height = parseFloat(elem.clientHeight) - paddingsHeight;
}
Example

I have a nice way to speed up scatter plots in d3 if someone can help me with panning

This is related a question I posted earlier
d3 got slow all of a sudden
In that question, I pointed out a slowdown in d3.js that happened a few versions back (3.2). The slowdown is most noticeable in IE, but is definitely there in other browsers as well. The problem comes up when clicking the mouse, and it takes a long time (2.5 seconds in IE) before the mouse event even gets to our code. The problem is caused by the amount of data in the plot. Simple scatterplots do not have this problem.
No answers were forthcoming on the topic, so I am solving the problem a different way. I am using nested divs like this:
<div class = "plot_container" id = "thing_plot_container">
<div class = "ghost_container" id = "thing_ghost_container"></div>
</div>
And this set of styles:
div.plot_container {
position: relative;
margin:0px; padding:0px; /* insurance */
border: none;
}
div.ghost_container {
position: absolute;
margin:0px; padding:0px; /* insurance */
top: 0px;left: 0px;
width:0px; height:0px; /* width and height are irrelevant */
overflow: visible; /* insurance */
border: none;
}
This lets me put my d3.js plot in the outer plot_container div and a separate div in ghost_container that I attach mouse events to.
Here is the rest of the relevant code. First the main d3 svg:
var div = d3.select("body").append("div")
.attr("class","tooltip")
.style("opacity",0);
var viewportWidth = window.innerWidth - 40;
var viewportHeight = window.innerHeight - 80;
var svg = d3.select("#thing_plot_container").append("svg")
.attr("id", "mySVG")
.attr("width",viewportWidth)
.attr("height",viewportHeight)
.call(zoom)
.on("dblclick.zoom", null)
//.on("mousewheel.zoom", zoomFun)//for FF
.on("DOMMouseScroll.zoom", zoomFun)//for FF(1.7 or earlier)
.on("wheel.zoom", zoomFun)
.append("g")
.attr("class", "main")
.attr("transform","translate("+(left_shift)+","+(top_shift)+")");
And this is the ghost div overlaying the regular div:
//
// set up ghost/overlay svg element to handle mouse clicks
//
var use_overlay = true;
var catcherWidth = viewportWidth;
var catcherHeight = viewportHeight;
var svgns = "http://www.w3.org/2000/svg";
if (use_overlay == true){
var mouse_div = document.getElementById('thing_ghost_container');
var mouse_svg_container = document.createElementNS(svgns, "svg");
console.log('replace these magic numbers with viewportWidth and height');
mouse_svg_container.setAttribute("width",catcherWidth+"px"); // clips on chrome/ff if not done this way
mouse_svg_container.setAttribute("height",catcherHeight+"px");
mouse_div.appendChild(mouse_svg_container);
var rect_mouse = document.createElementNS(svgns, "rect");
rect_mouse.setAttribute("x",0);
rect_mouse.setAttribute("y",0);
rect_mouse.setAttribute("fill","blue");
rect_mouse.setAttribute("fill-opacity",0.05); // set this to 0.0 when working
rect_mouse.setAttribute("width", catcherWidth+"px");
rect_mouse.setAttribute("height", catcherHeight+"px");
rect_mouse.setAttribute("onclick", "ghost_click(evt)"); // this HAS to be evt to get all browsers cooperating
// leaving these mouse down/mouseup events to the original svg does not work. The overaly svg kills it
rect_mouse.setAttribute("onmousedown", "ghost_mousedown(evt)");
rect_mouse.setAttribute("onmouseup", "ghost_mouseup(evt)");
mouse_svg_container.appendChild(rect_mouse)
}
This works very well as far as it goes. This completely sidesteps the slowdown issue with element-heavy plots like scatter plots. The mouse click event immediately gets served this way. The problem is that I cannot grab with the mouse and pan my chart! I need help getting the mouse events passed into the d3 pan/zoom code.
Here is a fiddle showing what I have so far:
https://jsfiddle.net/pkrouse/5sbqchnn/

Template: Preview as background image

I need for Fine Uploader to be able to drawThumbnail as a background image or to otherwise create scaled and cropped squares.
Basically, I am trying to reproduce the behavior I used in angularjs / flowjs, which was (more or less):
// I modified flowjs to set the background-image here instead of src with the base64 image.
<div ng-repeat="file in $flow.files" flow-img background-size: 'cover'">
This is the API on how to draw a thumbnail, but it specifically states that it returns a img or canvas. Instead, I'd like it set to the css property background-image.
http://docs.fineuploader.com/branch/master/api/methods.html#drawThumbnail
This solution gets close, but does not achieve the same effect as background-size: cover.
#image {
width: 33%;
padding-top: 33%;
position: relative;
}
#image canvas {
position: absolute;
top: 0;
bottom: 0;
}
...
callbacks: {
onSubmit: function(id, fileName) {
var canvas = document.createElement('canvas');
canvas.width = 500;
canvas.height = 500;
$('#image').html(canvas);
this.drawThumbnail(id, canvas, 500, false);
}
Using the UI mode give me exactly the same issue, I can only use it as the src like so:
<img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
This is my preferred solution...
#image {
width: 33%;
padding-top: 33%;
position: relative;
background-size: cover;
}
...
callbacks: {
onSubmit: function(id, fileName) {
this.drawThumbnail(); // somehow onto the background property of #image
}
Another solution, if widely adapted, would be to use elements as backgrounds (because then I could use the canvas for the #image background), but as of right now this is not a practical solution:
https://developer.mozilla.org/en-US/docs/Web/CSS/element
Another solution would be to watch for changes on the $('#image img').attr('src'). Hide the img element and set the background-image of #image on change. But, that's another ridiculous solution when the encoded image is right there.
If there isn't already a way to do this with fine uploader, why restrict the element of type img? Why not take any element and any attribute? Why not just return the base64 image and let us set it to any attribute?
Thanks in advance.
It sounds like the easiest solution would be to ask Fine Uploader to generate a thumbnail, pass the API method a temporary <img>, grab the src attribute from the <img> and use that to construct the background-image.
For example:
callbacks: {
onSubmit: function(id) {
var tempImg = document.createElement('img'),
self = this;
this.drawThumbnail(id, tempImg, 500).then(function() {
var fileContainerEl = self.getItemByFileId(id);
previewImg = fileContainerEl.getElementsByClassName('previewImg')[0];
previewImg.style['background-image'] = 'url("' + tempImg.src + '")';
});
}

Mouse hover applied to jQPLOT X AXIS TICKS

I am trying to add mouse hover function to my axis ticks.
what i want is to show long ticks full text only on hover else it would be showing only few characters . i am adding a hover event to .jqplot-xaxis-tick .But it doesnot even respond to hover.Please suggest !
.jqplot-xaxis-tick {
top: 0px;
/* initial position untill tick is drawn in proper place */
left: 15px;
/* padding-top: 10px;*/
vertical-align: top;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.jqplot-xaxis-tick :hover{
overflow:visible;
white-space: normal;
width: auto;
position: absolute;
background-color:yellow;
}
The hover is not detecting because of the z-index of the canvas which lies on top of the whole chart. I did the following and now it's shorten the tootip by CSS ellipsis and show the tooltip with full name on hover.
Based on the Gyandeep's answer, the exact JS and CSS I used are,
Javascript:
$('div.jqplot-xaxis-tick').each(function (i, obj) {
$(this).prop('title', ($(this).text()));
$(this).css('z-index', 999); // this is important otherwise mouseover won't trigger.
});
CSS:
.jqplot-xaxis .jqplot-xaxis-tick {
position: absolute;
white-space: pre;
max-width: 92px; // Change it according to your need
overflow: hidden;
text-overflow: ellipsis;
}
The JavaScript part needs to be executed after every rendering of chart. It's better to put them right after plotting the chart and may in the AJAX success handler.
I managed to add a tooltip kindof feature to axis ticks.When I hover upon them it shows a separate box with full text else only 3-4 characters are shown.
The code is something like this
$($('.jqplot-xaxis-tick')[i]).bind('mouseover', function () {
// var m= '-webkit-marquee';
$($('.jqplot-xaxis-tick')[i]).css('white-space','pre-line');
$($('.jqplot-xaxis-tick')[i]).css('overflow','visible');
$($('.jqplot-xaxis-tick')[i]).css('width','auto');
$($('.jqplot-xaxis-tick')[i]).css('position','absolute');
$($('.jqplot-xaxis-tick')[i]).css('background-color','#666666');
$($('.jqplot-xaxis-tick')[i]).css('color','white');
$($('.jqplot-xaxis-tick')[i]).css('top','-45px');
// $($('.jqplot-xaxis-tick')[i]).css('overflow-x',m);
// console.log($($('.jqplot-xaxis-tick')[i]).text());
}).bind('mouseout', function () {
//var m= '';
//$($('.jqplot-xaxis-tick')[i]).css('overflow-x',m);
$($('.jqplot-xaxis-tick')[i]).css('white-space','nowrap');
$($('.jqplot-xaxis-tick')[i]).css('overflow','hidden');
$($('.jqplot-xaxis-tick')[i]).css('width','50');
$($('.jqplot-xaxis-tick')[i]).css('background-color','');
$($('.jqplot-xaxis-tick')[i]).css('color','grey');
$($('.jqplot-xaxis-tick')[i]).css('top','0px');
});
Here's the solution I'm using to display monthly high and low temperatures. Hovering over the x-axis tick will display an alert with the active month name and temps.
// Set up hover function
$('#monthlyTemps .jqplot-xaxis-tick').hover(function () {
setActiveColumn($(this));
});
// Set active column
function setActiveColumn(sender) {
// Display values
var monthName = sender.text();
var monthIndex = monthNames.indexOf(monthName);
var monthLowTemp = getMonthLowTemp(monthIndex);
var monthHighTemp = getMonthlHighTemp(monthIndex);
alert(monthName + ': ' + monthLowTemp + ' / ' + monthHighTemp);
}
// Get month low temp
function getMonthLowTemp(monthIndex) {
var value= $("#monthlyTemps .jqplot-point-label.jqplot-series-0.jqplot-point-" + monthIndex).text();
return value;
}
// Get month high temp
function getMonthlyHighTemp(monthIndex) {
var value= $("#monthlyTemps .jqplot-point-label.jqplot-series-1.jqplot-point-" + monthIndex).text();
return value;
}
var monthNames = new Array(12);
monthAbbreviations[0] = "Jan";
monthAbbreviations[1] = "Feb";
monthAbbreviations[2] = "Mar";
monthAbbreviations[3] = "Apr";
monthAbbreviations[4] = "May";
monthAbbreviations[5] = "Jun";
monthAbbreviations[6] = "Jul";
monthAbbreviations[7] = "Aug";
monthAbbreviations[8] = "Sep";
monthAbbreviations[9] = "Oct";
monthAbbreviations[10] = "Nov";
monthAbbreviations[11] = "Dec";

C# created bitmap does not get displayed in Internet Explorer 8 (Firefox works fine)

I have problems to display a bitmap which I create in my C# Application. I create following bitmap:
int w = 150;
int h = w/3;
Bitmap aBMP = new Bitmap(w, h);
using (Graphics G = Graphics.FromImage(aBMP))
{ ...G.FillRectangle(...) } //here I am painting an image
later in the application I am saving the image as following:
aBMP.Save(anIMGfilename);
By a right click on the resulting image properties I dont receive the sercurity tab which I get with any other Bitmap image. Have you ever seen this behavior?
When you use position absolute you must not use float,and u must set left and top and its parent has a position relative
<!--[if IE 8]>
#frame{
position:relative;
}
#image {
position: absolute;
text-align: right;
height: 70px;
width: 400px;
left:0;
top:10px;
}
<![endif]-->

Resources