Resizing jwplayer7 iframe when orientation changes - css

I'm having an issue with JWP7, when the player is loading on portrait or landscape mode it stretches out to the full window as expected, but when changing the device orientation while the player is still playing, the player doesn't scaling the the new window dimensions.
Code example:
$('.player').height($window.height());
jwplayer("myElement").setup({
file: "somevideo.mp4",
width: windows.width,
height: windows.height,
});
<div id="player">
<div class="close_btn fadeIn"><img src="/img/close.png" width="50" /> </div>
<div id='player_frame'>
<iframe id=""video_iframe></iframe>
</div>
</div>
#media screen and (orientation:portrait) {
.video_iframe
{
height: 100vh;
overflow: hidden;
width: 100vw;
}
}
#media screen and (orientation:landscape) {
.video_iframe
{
height: 100vh;
width: 100vw;
}
}
Any suggestions?
Thank you all in advance.

There appear to be a few problems with your code:
1) The iframe ID attribute is not correctly enclosed with quotes:
<iframe id=""video_iframe></iframe>
should be:
<iframe id="video_iframe"></iframe>
2) Your CSS selectors are targeting using the class notation rather than by the element ID:
.video_iframe
{
height: 100vh;
overflow: hidden;
width: 100vw;
}
should be:
#video_iframe
{
height: 100vh;
overflow: hidden;
width: 100vw;
}
3) The "player" wrapper is likely to be restricting the height of the generated video player as the following is only being run once, and is probably setting an explicit pixel value:
$('#player').height($window.height());
Try removing this line.

I managed to fixed it with jQuery mobile - orientation change event:
$(window).bind( 'orientationchange', function(e){
var windowHeight = $(window).height() + 'px';
var windowWidth = $(window).width() + 'px';
if(window.orientation == 0) // Portrait
{
$("#myElement").height(windowHeight);
$("#myElement").width(windowWidth);
}
else // Landscape
{
$("#myElement").height(windowHeight);
$("#myElement").width(windowWidth);
}
});

Related

get only the numeric value of CSS variable, without its type

I want to make some calculation in CSS and use the result as a non-typed value.
This is what I've tried:
:root {
--scale: 100vh / 1920;
}
canvas {
height: 1920px;
width: 1080px;
transform: scale(var(--scale));
}
Nah, it didn't work, because --scale is some value in vh, like .8vh or 1.1vh, but I need it to be just a float, as .8 or 1.1.
Is there any way to use that variable without the type (vh), only with its numeric value? (I would prefer to do this with CSS only, without JS)
I need the initial values of height and width to be those, because I'll export the canvas as a png with that size, and scale does affect only the visualization, not the render of the canvas context.
Edit:
I've solved this with JS:
const resize = () => {
const ratio = (window.innerHeight) / 1920;
// container is a div wrapping the canvas
const containers = document.querySelectorAll('.container');
containers.forEach(container => {
const minMarginHeight = Math.min(0, (ratio - 1)/2 * container.clientHeight);
const minMarginWidth = Math.min(0, (ratio - 1)/2 * container.clientWidth);
container.style.transform = `scale(${ratio})`;
container.style.margin = `${minMarginHeight}px ${minMarginWidth}px`;
});
}
window.addEventListener('resize', () => {
resize();
});
but I was still looking for a pure CSS solution...
You can wrap canvas element with some wrapper (.wrapper in Code snippet) and define CSS --scale variable in .wrapper to 100%. In case of % it can be calculated in calc function and you will get your scale size.
body {
margin: 0;
}
.wrapper {
height: 100vh;
background: #673ab7;
--scale: calc(100% / 2);
}
canvas {
background: tomato;
transform: scale(var(--scale, 1));
height: 100%;
aspect-ratio: 16/9;
}
<div class="wrapper">
<canvas />
</div>

How to make content fit the full screen (Mapbox)

I'm using a map api (Mapbox). I'm trying to make the map fit the full screen, but nothing I try seems to work.
I have a wrapper and container for the map. I've tried to different solutions, but I'm still having problems.
Option 1: problem: the map doesn't fit the viewport, instead a scroll bar is added forcing the user to scroll down to view the entire map
jsfiddle #1
Option 2: problem: the map fills the entire viewport, but the bottom portion of the map is cut off (notice the mapbox logo is missing at the bottom)
jsfiddle #2
How can I get the map to fit the view port without being cutoff or adding a scroll bar?
Full code for reference:
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
class Application extends React.Component {
componentDidMount() {
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/light-v9', // stylesheet location
center: [13.392, 52.523], // starting position [lng, lat]
zoom: 9 // starting zoom
});
map.addControl(new mapboxgl.NavigationControl());
}
render() {
return (
<div>
<h2>Hello</h2>
<p>Hi</p>
<div className="map-wrapper">
<div ref={this.mapContainer} id="map"/>
</div>
</div>
)
}
}
ReactDOM.render(<Application/>, document.getElementById('app'));
body, html {
height: 100%;
}
.map-wrapper {
position: fixed;
width: 100%;
height: 100%;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100% !important.
}
<div id="app"></div>
No need for the wrapper. Simply set your height and width to 100vh and 100vw respectively.
#map {
width: 100vw;
height: 100vh;
}

set width and height of an image after transform: rotate

i have a div with width: 190px and height: 260px, i assign img tag on that div, when i upload an image that shows how the image before, after that i rotate the image but the width and height of the image didnt change like the div, i have used inherit, everything about position and display, but no good at all..
I have figured out an automated way as below:
First, I am getting natural height and width of the image (from onload trigger):
var naturalWidth = event.currentTarget.naturalWidth
var naturalHeight = event.currentTarget.naturalHeight
Then I am computing a transform scale using aspect-ratio and generating transform style as below (pseudo-code):
For 90deg (y-shift):
const scale = naturalWidth > naturalHeight ? naturalHeight / naturalWidth : 1;
const yshift = -100 * scale;
const style = `transform:rotate(90deg) translateY(${yshift}%) scale(${scale}); transform-origin: top left;`
For 270deg (x-shift):
const scale = naturalWidth > naturalHeight ? naturalHeight / naturalWidth : 1;
const xshift = -100 * scale;
const style = `transform:rotate(270deg) translateX(${xshift}%) scale(${scale}); transform-origin: top left;`
Hope this helps.
Inherit will not work.
Because you have to make the set the width of your image as the height of your parent. Then it will get completely resize in the parent element.
image-width = parent-height
Because after applying transform property width and height property will also get rotate in its respect.
Sol 1:
change the width of your image along with the transform property. (If it is variable then you can use the SCSS variables to assign the same values to the image-width and parent height.)
Sol 2:
This is not the perfect solution but will work in many cases. Add scale property to your transform property like this
transform: rotate(90deg) scale(.7);
Adjust the scale values according to you.
Hey,
Please Try this code.
var $=jQuery.noConflict();
$(document).ready(function(){
$('#RotateButton').click(function(){
$('.col').toggleClass("afterRot");
});
});
/* ----- IE Support CSS Script ----- */
var userAgent, ieReg, ie;
userAgent = window.navigator.userAgent;
ieReg = /msie|Trident.*rv[ :]*11\./gi;
ie = ieReg.test(userAgent);
if(ie) {
$(".col").each(function () {
var $container = $(this),
imgUrl = $container.find("img").prop("src");
if (imgUrl) {
$container.css("backgroundImage", 'url(' + imgUrl + ')').addClass("custom-object-fit");
}
});
}
body { padding: 0; margin: 0; }
.col { position: relative; display: block; width:100vh; height: 100vh; }
.afterRot{ transform: rotate(90deg); object-fit: cover; }
.col img { position: absolute; top: 0; left: 0; right: 0; width: 100%; height: 100%; object-fit: cover; }
.custom-object-fit { position: relative; background-size: cover; background-position: center center; }
.custom-object-fit img { opacity: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mob">
<button type="button" id="RotateButton"> Rotate </button>
<div class="col">
<img class="nor" id="rowImg" src="https://cdn-images-1.medium.com/max/1600/1*tSyuv3ZRCfsSD5aXB7v8DQ.png">
</div>
</div>
I think this is because you are not removing the class already associated with the Image. Try adding this to your button
$(document).ready(function(){
$('#RotateButton').click(function(){
$('#rowImg').removeClass("normalx").addClass("afterRot");
});
});
for a css like
.col {
width:260px;
height:190px:
border: solid 1px #6c757d;
padding: 10px;
}
.nor{
width:250px;
height:150px;
}
.afterRot{
width:inherit;
transform: rotate(90deg);
}
I have a sample here

Changing fixed width div using media queries in fluid layout

I'm using FlexSlider to display multiple 170px wide logos in a responsive design. Currently the slider fills 100% of the fluid width of the containing div, which is contained in the overall page wrapper, but this frequently leads to half cut off pictures. I'd like instead for the slider to resize in fixed widths, so that the logos are displayed without being cut off- desktop size would show 5 logos, tablet 4, etc. However, the media queries do not seem to be affecting it all, so all I'm left with is the original width (850px) that quickly becomes too big for the screen size. Is there something I'm missing? Is it possible to mix fluid CSS with a fixed width item like this?
Slider structure:
<div class="contentwrap">
[Omitted rest of the page content]
<div class="sliderwrap">
<div class="flexslider carousel">
<ul class="slides">
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
</ul>
</div>
</div>
</div>
CSS:
.contentwrap {
width: 85.5%;
margin: 0 auto;}
.sliderwrap {
width: 850px;
margin: 0 auto;}
#media screen and (max-width: 659px) {
.contentwrap {
width: 100%;
}
#media screen and (max-width: 169px) {
.sliderwrap {
display: none;
}
#media screen and (min-width: 170px) and (max-width: 339px) {
.sliderwrap {
width: 170px;
}
#media screen and (min-width: 340px) and (max-width: 509px) {
.sliderwrap {
width: 340px;
}
#media screen and (min-width: 510px) and (max-width: 794px) {
.sliderwrap {
width: 510px;
}
#media screen and (min-width: 795px) and (max-width: 995px) {
.sliderwrap {
width: 680px;
}
#media screen and (min-width: 170px) {
.sliderwrap {
width: 850px;
}
You must use Carousel With Min & Max Ranges
Example - http://jsfiddle.net/Luu3c2wk/
Code:
jQuery(document).ready(function($) {
// store the slider in a local variable
var $window = $(window),
flexslider;
// tiny helper function to add breakpoints
function getGridSize() {
return (window.innerWidth < 340) ? 1 :
(window.innerWidth < 510) ? 2 :
(window.innerWidth < 800) ? 3 :
(window.innerWidth < 995) ? 4 : 5;
}
$('.flexslider').flexslider({
selector: ".slides > div.flex-col",
animation: "slide",
animationLoop: false,
itemWidth: 100,
itemMargin: 0,
minItems: getGridSize(), // use function to pull in initial value
maxItems: getGridSize(), // use function to pull in initial value
start: function(slider){
flexslider = slider;
}
});
// check grid size on resize event
$window.on('resize', function() {
var gridSize = getGridSize();
console.log(gridSize);
flexslider.vars.minItems = gridSize;
flexslider.vars.maxItems = gridSize;
});
});

Zooming in overflow: scroll

I am trying to implement correctly scaling and zooming in css way. I created an example with scaled view. When click, the view should be zoomed and then to be able to scroll.
https://jsfiddle.net/opb5tcy8/4/
I have several issues with it:
Can I somehow get rid of the margin-left and margin-top on the .zoomed class? I did not manage to scale it without necessity to shift it with these margins.
When clicked, I can get the click position by clientX. I would like to use it to fluently scroll to the clicked position during zooming. However I can't manage the scroll to be fluent and when removing the margin-left it is kind of jumpy and not nice.
When you zoom in and move the scroll to the center and then zoom out, you can see the zoom is not nice as it first scrolls to the right. Is there a way to prevent it?
When you scroll to corners in Chrome on OSX it tends do navigate back/forward in browser. Is there a way to prevent this behaviour?
UPDATE:
The first part can be solved with transform-origin: 0 0. The other issues stays mostly the same as it is demonstrated.
Hm... I could say it is impossible to satisfy point 2 your condition with current browsers' support. The other are possible, as in this demo:
$(document).ready(function() {
var windowHalfWidth = $("#window").width() / 2;
var scalingFactor = 0.55;
var throtte = false;
$("#slider").click(function(event) {
//Simple event throtte to prevent click spamming breaking stuff up
if (throtte) return false;
throtte = true;
setTimeout(function() {
throtte = false;
}, 1000);
var xSelf = event.pageX - $("#window").offset().left + $("#window").scrollLeft();
if ($(this).hasClass("zoomed")) {
$("#window").animate({
scrollLeft: (xSelf / scalingFactor - windowHalfWidth)
}, 1000, "linear");
} else {
$("#window").animate({
scrollLeft: (xSelf * scalingFactor - windowHalfWidth)
}, 1000, "linear");
}
$("#slider").toggleClass("zoomed");
});
});
body {
background-color: #eee;
margin-top: 10px; /*reduced margin for easier view in SO */
}
#window {
width: 500px;
height: 200px;
margin: 0 auto;
overflow-x: auto;
overflow-y: hidden;
border: 1px solid #999;
position: relative;
background-color: white;
}
#slider {
width: 900px;
height: 600px;
background-color: #fff;
position: absolute;
transition: 1s linear;
top: 0;
left: 0;
transform-origin: 0 0;
}
#slider.zoomed {
transform: scale(0.55);
}
#slider div {
width: 50px;
height: 50px;
line-height: 50px;
position: absolute;
top: 75px;
background-color: #eee;
text-align: center;
}
#obj1 {
left: 10px;
}
#obj2 {
left: 210px;
}
#obj3 {
left: 410px;
}
#obj4 {
left: 610px;
}
#obj5 {
left: 810px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="window">
<div id="slider" class="zoomed">
<div id="obj1">1</div>
<div id="obj2">2</div>
<div id="obj3">3</div>
<div id="obj4">4</div>
<div id="obj5">5</div>
</div>
</div>
As you can see, the zooming & scrolling is quite laggy, especially when the far right size is zoomed in.
The reason is simple, because jQuery and css both have their own animation loop, and they are not in sync. In order to solve this we'll need to somehow manage to do both scrolling & scaling animations with only one system, either jQuery or CSS.
Problem is: jQuery don't have a scaling feature, and css can't scroll elements. Wonderful.
If your scaling can be done with width/height though, it would be possible, using jquery width&height animate(). But if the #slider consists of many components I guess it can't be done.
So um writing an answer just to say it's impossible is kind of a let down, so I think maybe I can suggest an alternative, using dragging to scroll content (similar to the way Google map work):
var windowHalfWidth, startX, startLeft, minLeft, dragging = false,
zooming = false;
var zoomElement = function(event) {
var xSelf = event.pageX - $("#window").offset().left - parseFloat($("#slider").css("left"));
if ($("#slider").hasClass("zoomed")) {
minLeft = windowHalfWidth * 2 - 900;
var newLeft = Math.min(Math.max((-(xSelf / 0.55 - windowHalfWidth)), minLeft), 0);
$("#slider").css("left", newLeft + "px");
} else {
minLeft = windowHalfWidth * 2 - 900 * 0.55;
var newLeft = Math.min(Math.max((-(xSelf * 0.55 - windowHalfWidth)), minLeft), 0);
$("#slider").css("left", newLeft + "px");
}
$("#slider").toggleClass("zoomed");
}
$(document).ready(function() {
windowHalfWidth = $("#window").width() / 2;
minLeft = windowHalfWidth * 2 - 900 * 0.55;
$("#slider").on({
mousedown: function(event) {
dragging = true;
startX = event.pageX;
startLeft = parseFloat($(this).css("left"));
},
mousemove: function(event) {
if (dragging && !zooming) {
var newLeft = Math.min(Math.max((startLeft + event.pageX - startX), minLeft), 0);
$("#slider").css("left", newLeft + "px");
}
},
mouseup: function(event) {
dragging = false;
if (Math.abs(startX - event.pageX) < 30 && !zooming) {
// Simple event throtte to prevent click spamming
zooming = true;
$("#slider").css("transition", "1s");
setTimeout(function() {
zooming = false;
$("#slider").css("transition", "initial");
}, 1000);
zoomElement(event);
}
},
mouseleave: function() {
dragging = false;
}
});
});
body {
background-color: #eee;
margin-top: 10px; /*reduced margin for easier view in SO */
}
#window {
width: 500px;
height: 200px;
margin: 0 auto;
overflow: hidden;
border: 1px solid #999;
position: relative;
background-color: white;
}
#slider {
width: 900px;
height: 600px;
background-color: #fff;
position: absolute;
top: 0;
left: 0;
transform-origin: 0 0;
}
#slider.zoomed {
transform: scale(0.55);
}
#slider div {
width: 50px;
height: 50px;
line-height: 50px;
position: absolute;
top: 75px;
background-color: #eee;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#obj1 {
left: 10px;
}
#obj2 {
left: 210px;
}
#obj3 {
left: 410px;
}
#obj4 {
left: 610px;
}
#obj5 {
left: 810px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="window">
<div id="slider" class="zoomed">
<div id="obj1">1</div>
<div id="obj2">2</div>
<div id="obj3">3</div>
<div id="obj4">4</div>
<div id="obj5">5</div>
</div>
</div>
This variation manages to get CSS to do both animation, by sacrificing the scrollbar (which is pretty ugly imo, who needs it?) and use css left instead.
So I hope if in the end you can't find a good solution, at least you have this to consider as fall back version.
I'll address the points individually and then give an example at the end.
When clicked, I can get the click position by clientX. I would like to
use it to fluently scroll to the clicked position during zooming.
In my opinion scroll animations during transitions can be a bit choppy in webkit browsers. Try balancing the animation time of the jQuery effect with the animation time of the css transition.
When you zoom in and move the scroll to the centre and then zoom out, you can see the zoom is not nice as it first scrolls to the right. Is there a way to prevent it?
Bring the scrollLeft property of the div#window back to 0px. Again, tweaking the animation times will make this less jerky.
When you scroll to corners in Chrome on OSX it tends do navigate back/forward in browser. Is there a way to prevent this behaviour?
You could use the mouseover and mouseout events to toggle a overflow:hidden css on the body.
Here's an example change to your code:
var slider = $("#slider").on('click', function(event) {
if (!slider.hasClass('zoomed')) {
// zoom back to left position
$('#window').animate({scrollLeft:'0px'});
}else{
// zoom to click position within slider
$('#window').animate({scrollLeft:event.clientX + 'px'}, 2000);
}
slider.toggleClass("zoomed");
});
/* stop window scrolling when using slider */
slider
.on('mouseover', function () {
$(document.body).css({overflow:'hidden'});
})
.on('mouseout', function () {
$(document.body).css({overflow:'auto'});
});
And an updated fiddle.

Resources