I have an iFrame that displays an advertisement 990x90.
I want to make it so mobile viewers can still see the ad, but I need the iframe to resize "evenly", for example, if screen width is 900 I need the hight to be proportionate.
Please help :)
It'd of been so practical if you wrote the code you tried to do what you are asked for so that guys on here can help you as it is hard to guess what your code/goal is or to build it from scratch, However for this time, here is the code you need to achieve what you are asking for as you can see it in action in this JSFiddle, and here's the code needed:
JS:
iFrameOriginalWidth = $('iframe').width();
OnResize();
$(window).resize(function() {
OnResize();
});
function OnResize(){
var winWidth = $(window).width();
if(winWidth < 900){
$('iframe').css({'max-width':'100%'});
}else{
$('iframe').css({'max-width':iFrameOriginalWidth});
}
}
HTML:
<h2>Welcome to my iFrame</h2>
<iframe src="http://www.coffeeipsum.com" width="1100" height="300" frameborder="0" scrolling="no" />
Related
I have used the vimeo generated code to embed my video in a wix website (using their HTML component tool). I've tweaked the code so it autoplays when the page loads, and it is responsive on resizing the browser window (plus full width on the webpage). The code used is:
<div style="padding:42.6% 0 0 0;position:relative;">
<iframe src="https://player.vimeo.com/video/558081433?autoplay=1&muted=1&loop=1&autopause=0"
frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen
style="position:absolute;top:0;left:0;width:100%;height:100%;" title="Anthemic Piano">
</iframe></div><script src="https://player.vimeo.com/api/player.js"></script>
I saw someone use some neat code to add an unmute button to their video, but the code generates a very small video area on the website, rather than the full width, responsive version I'm trying to get. Here is the code they used:
<button onclick="unmute()">
UNMUTE
</button>
<div id="vimeo-player1"> </div>
<script>
var options = {
id: 194500280,
background: true
};
var vid1 = new Vimeo.Player('vimeo-player1', options);
</script>
<script>
function unmute() {
vid1.setVolume(1);
};
</script>
I tried adding in
width: 100%
to the var options = {} part of the code, but this doesn't work to make it responsive/full width.
I'd be incredibly grateful if someone was able to help amalgamate my original code, with the unmute button code so I can finally get it working. Thank you so much for your help with this.
Setting the CSS width for container and iframe must help. The code below shows the video in full-width and UNMUTE button works as expected.
<style>
.container {
height:95%;
width:100%;
}
.container iframe{
width: 100%;
height: 100%;
}
</style>
<script src="https://player.vimeo.com/api/player.js"></script>
<div class="container" id="vimeo-player1"> </div>
<button onclick="unmute()">
UNMUTE
</button>
<script>
var options = {
id: 558081433,
background: true,
muted:1,
loop:1
};
var vid1 = new Vimeo.Player('vimeo-player1', options);
vid1.play();
</script>
<script>
function unmute() {
vid1.setVolume(1);
};
</script>
I need to change zoom rate on different breakpoint for embed google my map. Map is embed in iframe like this
<iframe src="https://www.google.com/maps/d/embed?mid=ID_here&z=15" width="100%"></iframe>
As you can see, zoom is 15, but I need to change it on mobile and tablet devices.
Do you have idea how to do that?
Perhaps something like this:
<!DOCTYPE html>
<html>
<head><title>test</title></head>
<body>
<iframe
width="600"
height="450"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?key=AIzaSyBu9SPYB9qp2PTe1M1_TyBAQN4c-yL8HYQ
&q=Space+Needle,Seattle+WA&zoom=10" allowfullscreen>
</iframe>
<script>
function setEmbeddedMapZoom() {
var zoomForPhone = 15;
var defaultZoom = 10;
var baseSrc = 'https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q=Space+Needle,Seattle+WA&zoom=';
if (window.innerWidth < 1600) {
document.getElementsByTagName('iframe')[0].setAttribute('src', baseSrc + zoomForPhone);
} else {
document.getElementsByTagName('iframe')[0].setAttribute('src', baseSrc + defaultZoom);
}
}
window.addEventListener('resize', setEmbeddedMapZoom);
</script>
</body>
</html>
http://jsbin.com/tucanayiye/edit?html,output
Please note that I had to make sure the Embed API was turned on in the project where I created the API key.
I am using fabric js and canvas to add image from url I want to make canvas and containing image responsive as per resolution.How can we do it?
my code is:-
<canvas id="panel" width="700" height="350"></canvas>
<script>
(function() {
var canvas = new fabric.Canvas('panel');
var rect;
fabric.Image.fromURL('abc.jpg', function (img) {
canvas.add(img.set({
width: canvas.width,
height:canvas.height,
originX :'left',
originY :'top',
selectable: false,
}));
});
})();
</script>
As per my knowledge there are no inbuilt functions to achieve this.
But canvas can be made responsive by using native javascript and playing with the screen width and screen height, setting them as canvas width and height.
And same maths you have to apply for all the items drawn in the canvas. (take the ratio of your canvas width or height to screen width or height and use this ratio to resize all the elements on change of view-ports).
Hope it will help you.
I include the YouTube player as follows in my php file but the player does not show the fullscreen button. Switching to the flash player works (whether through changing the url from /embed to /v or by disabling &html5=1). What am I doing wrong?
An example is available here: http://jonnyrimkus.square7.ch/stuff/youtube_html5_fullscreen.php
<script>
var tag = document.createElement(\'script\');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName(\'script\')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
player = new YT.Player(\'player\', {
playerVars: {
\'allowfullscreen\': \'true\',
\'allowscriptaccess\': \'always\'
},
events: {
\'onReady\': onYouTubePlayerReady,
\'onStateChange\': playerStateChange,
\'onError\': playerStateError
}
});
}
</script>
<iframe id="player" width="425" height="356" border="0" frameborder="0" src="http://www.youtube.com/embed/36XdO9Iv9ew?enablejsapi=1&playerapiid=lastfmplayer&autoplay=1&html5=1&fs=1&origin=http://jonnyrimkus.square7.ch"></iframe>
The fullscreen button will also not be visible if the Youtube player is inside another iframe that does not have allowfullscreen attribute.
Unlike what Google's documentation says(as of 11/2014), the fs attribute in querystring does not seem to influence the visibility of fullscreen. The visibility seems to be influenced by allowfullscreen attribute in iframe which youtube player puts by default during instantiation. That said, if your embed the player inside another iframe you should also mark that iframe for allowfullscreen ( or all its variants webkitallowfullscreen mozallowfullscreen)
<iframe src='' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen>
<!-- YT player-->
</iframe>
The way you are using the iframe api now does nothing, the api is made to bind on an empty element, like <div id="player"></div>, the id is the first argument in the new YT.Player function.
In order to load a youtube video with the iframe api you need this in the body:
<div id="player"></div>
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: 480,
width: 640,
videoId: "36XdO9Iv9ew",
});
}
</script>
There is no need to explicitely specify you want to enable fullscreen when using the iframe api.
You can also just use the iframe without the api, you'll need to specify you want fullscreen when you use it.
<iframe width="640" height="480" frameborder="0" id="player" allowfullscreen="1" title="YouTube video player" src="http://www.youtube.com/embed/36XdO9Iv9ew?enablejsapi=1"></iframe>
Just using the iframe tag is a bit faster, but if you want to use the extra features of the iframe api you have no choice.
A page with examples (also check the source): http://qnet.co/yt
You can also implement the fullscreen feature yourself (not needed for Youtube, but still cool):
var goFullscreen = function(id) {
var el = document.getElementById(id);
if (el.requestFullScreen) {
el.requestFullScreen();
} else if (el.mozRequestFullScreen) {
el.mozRequestFullScreen();
} else if (el.webkitRequestFullScreen) {
el.webkitRequestFullScreen();
}
}
var leaveFullscreen = function() {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
and to make the Youtube player go fullscreen with: goFullscreen('player'), and leave fullscreen with: leaveFullscreen()
The different versions of requestFullscreen and cancelFullscreen are for different browsers, because the standard is not yet completely finished
More info on Javascript Fullscreen: http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/ (relative old document, but still valid)
off-topic: It is useless to echo such a string with php, you can just paste it in the body the file outside of the php tags.
This is still an issue in July 2014, and you just wonder if Google will ever fix this. Actually you can force the Flash player in another way at the client end by using a UA Spoofer, and for Google Chrome browser for instance, Chrome Web Store - djflhoibgkdhkhhcedjiklpkjnoahfmg and then spoof a browser that doesn't understand HTML5.
Actually HTML5 video is still a disaster, and the grainey spikey-jaggy edges to the video and the herringbone patterning though faint is still distracting. Whereas Flash is Smooth, Flawless, Reliable, and Sharp edges with zero patterning artifacts.
HTML5 - still big thumbs down, I wouldn't inflict it on users.
Oh yes and still Fullscreen not appear in embeds like this
Rick Astley - Never Gonna Give You Up # viewpure embed
http://viewpure.com/dQw4w9WgXcQ
You can use the above example to fiddle and diddle with different browser plugins.
SO I know this solution is somewhere but I can't find it. I've been digging for about a day into google and stackOverflow.
Basically, I have an iframe and I'm trying to get it to expand to the size of its contents, a pretty simple task. I went through several methods, looking at different heights etc. But for some gosh darn reason, Chrome does not want to put up with me.
So here is the javascript to resize the IFrame. To make sure JS was working and to read the height I threw in that innerHTML piece (sort of like debugging)
<script type="text/javascript">
function resizeFrame() {
var t=document.getElementById("Footer");
var f = document.getElementById("mainContent");
var y = f.contentWindow;
t.innerHTML = y.document.body.offsetHeight;
f.height = y.body.offsetHeight;
}
</script>
Here's the iframe:
<iframe onload="resizeFrame()" id="mainContent" src="homec.html" scrolling=auto frameborder=0 height="100%" width="100%">
Not working!</iframe>
So for some odd reason, it does not want to work, pretty much hates me in Chrome. But it works in Firefox and IE. Any solutions??
Unless I'm missing something, I believe you have a typo on the last line of your function (missing .document.)
The following works for me in Chrome (18.0):
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function resizeFrame() {
var t=document.getElementById("Footer");
var f = document.getElementById("mainContent");
var y = f.contentWindow;
t.innerHTML = y.document.body.offsetHeight;
f.height = y.document.body.offsetHeight;
}
</script>
</head>
<body>
<iframe onload="resizeFrame()" id="mainContent" src="homec.html" scrolling=auto frameborder=0
height="100%" width="100%">Working!</iframe>
<p id="Footer"> Footer</p>
</body>
</html>