Is it possible to constrain the aspect ratio of a window in an NW.JS app?
I have content which is 800 x 600. In the package.json manifest, I can define the window settings as...
"window": {
"toolbar": false
, "width": 800
, "height": 600
, "min_width": 800
, "min_height": 600
}
I use CSS to preserve the aspect ratio of the content and to fill the window as well as possible:
html, body{
margin: 0;
height: 100%;
}
main {
position: relative;
width:100vw;
max-width:133.3333vh; /* max-width / width = aspect ratio */
min-width: 800px;
height:75vw;
max-height:100vh; /* max-height / height = aspect ratio */
min-height: 600px;
margin: 0 auto;
}
However, if you make the window too wide, a blank area appears on either side. If you make it too tall for its width, a blank area appears at the bottom.
Is there a setting that forces a given aspect ratio?
Or is there now a window resize event that I can listen for so that I can apply window.resizeTo(height*1.333,height) as soon as the window's size is changed?
There does appear to be a resize event:
https://github.com/nwjs/nw.js/issues/799
https://github.com/nwjs/nw.js/wiki/window
You could use code like this to set your event listener:
gui = require('nw.gui');
w = gui.Window.get();
w.on('resize', yourFunctionHere);
but be careful about changing the window size in the handler (e.g. using resizeTo()) as that will trigger a resize and could cause all kinds of chaos. It might work to make the resize conditional on the current aspect ratio, but I can imagine you could still run into problems if you hit some limit or other. Offhand I don't know if there are some facilities (akin to event bubbling &c) that would help in this situation.
Related
As you can see from the image, the iframe content is too big and it hides the X button + Sources bar.
Is there any option to make it's content a bit smaller?
This css seems to be the problem:
##media only screen and (min-width: 767px) {
#uw-glamor-396 .css-5anb0a, #uw-glamor-396 [data-css-5anb0a] {
position: absolute;
top: 50%;
left: 50%;
width: 767px;
height: 610px;
transform: translate(-50%, -50%);
border-radius: 5px;
}
}
If the height would be 450px instead of 610px it would fix the issue.
This fiddle raises the issue, open it with your laptop and expand a little bit the result window to get the Drag and Drop box.
This is how it looks like without the bookmark tab in my laptop with 100%, I use Chrome:
Unfortunately, it isnt possible to change this currently. Its a known issue but up until now there havent been any complaints that i know of. Typically apps that host the widget are in desktop resolutions so there's enough vertical space or its in mobile res and then the widget switches to the mobile layout.
Ill look into promoting this issue internally.
In the meantime, can you share some details about your app, how does it display the widget? What makes it not have enough vertical space?
Bootstrap 3:
I'm trying to float a button center halfway outside the panel-footer. But the whole layout is responsive so I need to have it when the screen size is resized or smaller it is still correct.
I created a bootply with my attempt that is close but doesn't stay when the screen is resized.
Thanks,
Nate
Bootply Trial
Is this what you wanted to get? http://www.bootply.com/114327
.relative {
position: relative;
}
.absolute {
position: absolute;
}
.bottom-btn {
left: 50%;
bottom: -17px; /* half of the button height */
margin-left: -77px; /* half of the button width */
/* instead of bottom and margin-left, you can use translateX as well. */
}
play with css position property and use margin to get exact position. see the comments for the .bottom-btn class.
I am customizing the title of the Magnific popup/lightbox to include more than one row of content by using the 'change' callback, and modifying the content of
this.content
within the callback. It is working correctly, except for the fact that if the image within the popup is very tall, or the window re-sizes to a smaller height, the calculation that Magnific is doing to adjust the 'max-height' of the image seems to only take into account a single row of text for the title.
Does anyone know what is needed to adjust the max-height calculation of the image to take into account a taller title box?
Thank you
** Edit
A quick hack to jquery.magnific-popup.js around line 461 in the "updateSize:" callback has allowed me to get around this problem. It seems reasonable to for this popup/lightbox to accept a max height in percentage so that it doesn't fill the screen.
Here's my change, I'd appreciate some feedback if possible. Thanks!
updateSize: function(winHeight) {
if(mfp.isIOS) {
// fixes iOS nav bars https://github.com/dimsemenov/Magnific-Popup/issues/2
var zoomLevel = document.documentElement.clientWidth / window.innerWidth;
var height = window.innerHeight * zoomLevel;
mfp.wrap.css('height', height);
mfp.wH = height;
} else {
mfp.wH = winHeight || _window.height();
// ########################################
// CHANGE IS RIGHT HERE TO FORCE 80% height
// ########################################
mfp.wH *= 0.8;
}
// Fixes #84: popup incorrectly positioned with position:relative on body
if(!mfp.fixedContentPos) {
mfp.wrap.css('height', mfp.wH);
}
_mfpTrigger('Resize');
},
You can limit the max height of the image in the resize callback, which will allow more room for the title:
$('a.magnific').magnificPopup({
type: 'image',
callbacks: {
resize: function() {
var img = this.content.find('img');
img.css('max-height', parseFloat(img.css('max-height')) * 0.95);
}
}
});
I'd like to add my contribution. As I wanted to include both titles and descriptions to images. This meant that I couldn't fit all this information in the viewport space. The description was cut off and I was left with a scrollbar.
#alexantd - I tried your callback addition which only works when the window is being resized.
#ajhuddy - Your solution worked perfectly for me. I was able to fit the text in fine. Though the image was considerably small with a lot of space at the top.
I adjusted the padding as to regain 40px space to display a slightly larger image. Here's my CSS to do so. The CSS below allowed me to reduce images to 0.85 (85%).
.mfp-img {
padding: 0px 0px 40px !important;
}
.mfp-close {
margin-top: -40px;
}
else b.wH=a||v.height()**,b.wH*=.9**;b.fixedContentPos
I have a div on my page containing images. As it is 800px high and situated 400px from the bottom of the page, my images are getting cut off from the top when viewed on smaller monitors. I am not using scrollbars on my website.
I have added some CSS to my div that zooms out/scales the content...
.hello {
width:100%;
height:800px;
position:fixed;
top:0;
bottom-margin:400px;
z-index:0;
-moz-transform: scale(.8);
-webkit-transform: scale(.8);
zoom : .8;
-moz-transform-origin:top center;
-webkit-transform-origin:top center;
}
But is there any script that I could implement that will only apply the zoom/scale if the user's monitor dimensions are 1200px high or smaller?
Thanks in advance for any help!
What you're looking for is the screen resolution. See here. Relevant bits:
height
Returns the height of the screen in pixels.
width
Returns the width of the screen.
However, this does not tell you how big the window is, in which case you'll need the windows dimensions. See here. Relevant bits:
window.innerHeight
Gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.
window.innerWidth
Gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.
I would detect this and change classes and whatnot appropriately.
Working URL:
http://webstage.co/scroll/stack.html
What I am trying to accomplish is to hide the content when it is outside of the background area (1280x800). I like the way the backgrounds are coming in when you scroll to a new section, but I want to hide the content until it gets into that 1280x800 viewport? Any suggestions on how I can accomplish this?
Bonus...It would be great if I could also hide the content under the top navigation once it scrolled up under it as well. A guy can dream. :)
Thanks!
For the first part you can add another div and target with css something like this:
.viewport {
width: 1280px;
height: 100%;
position: fixed;
top: 0;
left: 50%;
margin-left: -640px;
background: black;
clip: rect(800px, 1280px, auto, auto);
}
Basically, set the background to the same color as the page background and use clip to only display the portion of the div that sits below your desired viewport area hiding the content outside the viewport area.
If you add content to the footer later you may need to tweak some z-index settings to make sure it sits on top of the viewport div.