How to implement a responsive Youtube embed iframe with Twitter Bootstrap? - ruby-on-rails-3

Currently I'm embedding Youtube videos with the following HAML code in a Twitter Bootstrap based site:
.row
.span12
%iframe.span11{ :height => "720", :frameborder => "0", :allowfullscreen => nil, :src => v.video_url }
Unfortunately, this doesn't respond well when resizing the browser or on mobile devices because of the static height.
What would be a better (more dynamic and responsive) way to implement this embedded iframe for Youtube?

Try this "Responsive video CSS", it works perfect for me: https://gist.github.com/2302238
<section class="row">
<div class="span6">
<div class="flex-video widescreen"><iframe src="https://www.youtube-nocookie.com/embed/..." frameborder="0" allowfullscreen=""></iframe></div>
</div>
<div class="span6">
...
</div>
</section>

I implemented a pure CSS solution which works great.
Here is an example of code in my view using the iframe code generated in YouTube.
<div class="video-container">
<iframe width="300" height="168" src="http://www.youtube.com/embed/MY__5O1i2a0" frameborder="0" allowfullscreen></iframe>
</div>
Here is an example of code in another view where instead of using iframe I used the body field generated from the AutoHtml gem, which is used for embedding different types of video links into a web page. This is good if you have a model where a link needs to be dynamically embedded into the same web page.
<div class="video-container">
<span style="text-align: center;"><%= #livevideo.body_html %></span>
</div>
Here is the CSS code:
.video-container {
position: relative; /* keeps the aspect ratio */
padding-bottom: 56.25%; /* fine tunes the video positioning */
padding-top: 60px; overflow: hidden;
}
.video-container iframe,
.video-container object,
.video-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
Here is the YouTube video which explains in great detail how the code works and give one or two blog posts to check out.
http://www.youtube.com/watch?v=PL_R3zEjqEc

Bootstrap 3.2.0 comes with a several improvements and a large number of bug fixes. A framework for building websites with a responsive design, Bootstrap was missing support for responsive , and elements, feature added in this latest version.
The HTML for a responsive YouTube 16:9 video that adjusts its size based on the width of the page it is displayed in looks like this:
On your container(maybe DIV) add class="embed-responsive embed-responsive-16by9"

This is probably best done with jQuery: http://www.seanmccambridge.com/tubular/ or http://okfoc.us/okvideo/

Just to automatize #Bart's answer, I've created a simple Javascript snipped that automatically wraps iframe elements within <div class="flex-video">
$(document).ready(function() {
$('iframe').each(function() {
$(this).wrap('<div class="flex-video"></div>');
});
});

If using bootstrap, the method below is without a doubt the easiest way to implement a responsive embed:
<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
<!-- 4:3 aspect ratio -->
<div class="embed-responsive embed-responsive-4by3">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
Documentation can be found here: http://getbootstrap.com/components/#responsive-embed.

Related

How to set a Video Background in ASP .NetCore MVC Web Application

Currently, I am working on a ASP .NetCore project to make a web application. I face trouble in setting a video background for the entire application. There are plenty of methods to set a video background for ordinary Html/CSS projects but I was unable to find a reliable method to set up a video background for a ASP.net core MVC web application.
Project Details:
Framework: ASP .NetCore MVC web application
Target Framework: net 5.0
This is my project structure:The folder structure of the MVC web app
I was in a hurry to find a way to do this. I am sorry if the information provided by me are not sufficient. Yes, I have tried using simple available methods such as,
Using video tag in _layout.cshtml file as follows.
HTML code:
<div class="fullscreen-bg">
<video loop muted autoplay poster="images/background.jpg" class="fullscreen-bg__video">
<source src="../../wwwroot/video/background.mp4" type="video/mp4">
</video>
</div>
CSS code:
.fullscreen-bg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: -100;
}
.fullscreen-bg__video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
The video file is saved in images folder of wwwroot folder. It is a mp4 file.
I have tried several codes similar to above code, but it does not work in ASP.NETcore web app.
I ran into a similar problem, once. This could be solved by few codes added to the _layout.cshtml. Following is the method I followed to solve the issue. I hope this might help you to solve your issue, too.
I made the following changes in the _layout.cshtml file.
In _layout.cshtml you can find the following code snippet:
<div class="container">
<main role="main" class="pb-3">
#RenderBody()
</main>
</div>
Modify it as follows:
<div class="container embed-responsive">
<main role="main">
<div>
<video autoplay muted loop poster="">
<source src="" data-src="https://webtests.blob.core.windows.net/samplevideo/background.mp4" type="video/mp4">
</video>
<div class="container">
#RenderBody()
</div>
</div>
</main>
</div>
In the 'body' tag, add the bootstrap classes 'jumbotron' and 'jumbotron-fluid' as follows.
<body class="jumbotron-fluid jumbotron">
In the 'nav' tag, add the bootstrap class 'fixed-top' as follows (otherwise navbar is hidden under the layers and not clickable):
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 fixed-top">
Now, after the </html> tag at the end, add the following script.
<script>
function backgroundVideo() {
$("video source").each(function () {
var sourceFile = $(this).attr("data-src");
$(this).attr("src", sourceFile);
var video = this.parentElement;
video.load();
});
}
window.onload = backgroundVideo;
</script>
Next modify the bootstrap classes as follows. You may change the properties of the classes until the desired output is obtained.
<style>
.jumbotron {
background-color: #454545;
}
.jumbotron .hero-section {
position: fixed;
z-index: 1;
top: 0;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.6;
background: black;
}
.jumbotron .container {
z-index: 2;
position: relative;
}
</style>
If you may wonder how I get the 'data-src' URL for the video. It is very easy. Follow the steps below.
Create an Azure account for free. (you can use your university mail/GitHub student package or just use the credit card number)
Search for 'Azure blob storage' and create a 'container' with public access enabled. (This can be done when creating the container)
screenshot
Next upload the video file to blob storage and get the URL. screenshot
Now you can use that URL directly in the project.
You can further decrease the video file size using this online converter without affecting the quality: https://www.freeconvert.com/video-compressor
You can get the added benefit that your project size becomes less since the heavy media files are stored in the cloud.
This solved my problem. I hope you may use it wisely. Please feel free to suggest more. I am also learning and highly value your opinion.
I think it is the path problem, wwwroot is a web root path when you run it. So the path need to be changed as:
<source src="~/video/background.mp4" type="video/mp4">
Edit:
It is possible that browser has compatibility issues with the transcoded video. You can also use videojs.
<div>
<video id="my-video" class="video-js" controls preload="auto" width="1296" height="728"
poster="video/cover.png" data-setup="{}">
<source src="~/images/1.mp4" type="video/mp4" />
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that
supports HTML5 video
</p>
</video>
</div>
#section Scripts{
<link href="//vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
<script src="//vjs.zencdn.net/7.10.2/video.min.js"></script>
#*If you'd like to support IE8*#
#*<script src="http://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"> </script>*#
<script>
var my_video = videojs('my-video');
videojs('my-video').ready(function () {
var myvideo = this;
myvideo.play();
});
</script>
}

Adding a custom legend on mapbox - displays wacky

I am a designer, new to mapbox. (So, I may need things explained to me like I'm a four-year old, pretty please).
I created a map with labels using their plain editor (not Studio) and placed it on my page here.
I want to add a custom legend, possibly in a custom position. I tried using their example, but my map doesn't even show up at all. When I comment out mapbox's CSS link ref in the head, it almost works, but shows all wacky. See that one here.
Here's the added HEAD code per mapbox's legend example that I have on my page:
<script src="https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.js"></script>
<style>
body {
margin:0;
padding:0;
}
#map {
position:absolute;
top:0;
bottom:0;
width:100%;
}
.legend label,
.legend span {
display:block;
float:left;
height:15px;
width:20%;
text-align:center;
font-size:9px;
color:#808080;
}
</style>
Then here's the BODY code I added for the mapbox elements.
<div id="legend" style="display:none;">
<strong>The Title or Explanation of your Map</strong>
<nav class="legend clearfix">
<span style="background:#F1EEF6;"></span>
<span style="background:#BDC9E1;"></span>
<span style="background:#74A9CF;"></span>
<span style="background:#2B8CBE;"></span>
<span style="background:#045A8D;"></span>
<label>0 - 20%</label>
<label>40%</label>
<label>60%</label>
<label>80%</label>
<label>100%</label>
<small>Source: Name of source</small>
</nav>
</div>
<div id="map"></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoibW1hcm1vbCIsImEiOiIzZTkxMDM4ZDI5MDZiMDY2MzFlOGQ4YzZiYmY2NmMzOSJ9.Cr8JtBNsYIl3LTxYZkaFPA';
var map = L.mapbox.map('map', 'mmarmol.2a3461fc');
map.legendControl.addLegend(document.getElementById('legend').innerHTML);
</script>
All other code is Bootstrap for the rest of my page. It seems like I have a CSS issue, or is it a js issue? Any ideas?
Thank you!

ipad object scrollbar

first timer here. I help manage a WordPress site that has an html object imbedded in a div that overflows. The scrollbar functionality works fine on pc's; however, on an ipad (and I assume an iphone and android devices), the scrollbar doesn't appear. The html I have is:
#wrapper {
width:100%;
height:360px;
overflow:scroll;
-webkit-overflow-scrolling:touch;
}
#wrapper object {
width: 100%;
height: 100%;
}
<div id="wrapper">
<object id="object" type="text/html" data="[link to html page with lots of <tr> rows]"
</object>
</div>
I'm wondering if perhaps the webkit overflow attribute should be on the object instead of the div to get this to work correctly?

Entire slider jumps on load - AnythingSlider

I am using AnythingSlider to place content on this dev for a new site:
http://sitedev.lcadfiles.com/interactive_barrett.html
When the slider first loads on a given page, there is a slight jump (the entire slider, arrows, etc. moves a few pixels before settling into the correct position). After landing, it all appears to work fine. The shift doesn't appear to be browser specific, as it occurs on my older and newer machines with 4 different browsers (and various browser versions).
Is there something I have set wrong? I assume it might be somewhere global, like the anythingSlider.js (or perhaps the .css - though this seems less likely), but didn't see anything that stood out.
Had the same problem. A quick workaround (works for me).
eg. you have html code like below, add a style="visibility:hidden;" to your anythingslider container.
<div id="slider_nest" style="visibility:hidden;">
<ul id="your_anythingslider">
...
</ul>
</div>
in the js code, change the style to visible when document ready. eg.(JQuery)
jQuery(document).ready(function($) {
$('#slider_nest').css('visibility', 'visible');
...
$('#your_anythingslider').anythingslider();
...
}
Hope it helps!
Update: add a slider mask with a loader gif.
eg. in the html, you will have something like below:
<div id="slider_mask" style="background: #000 url('ajax-loader.gif') no-repeat center; display:block; height:568px; width:1050px; margin:0 auto;">
</div>
<div id="slider_nest" style="display:none; height:568px; width:1050px; margin:0 auto;">
<ul id="your_anythingslider">
...
</ul>
</div>
Now in the js (JQuery):
jQuery(document).ready(function($) {
$('#slider_mask').hide();
$('#slider_nest').css({'display':'block'});
...
OMG, this finally solved our problem! Thank you.
Since I'm using the Wordpress plugin on a custom theme, I had to adjust it a bit like this:
Add this before the shortcode in the header.php file:
<div id="slider_mask" style="background: #FFF url('ajax-loader.gif') no-repeat center;display:block; height:323px; width:940px; margin:0 auto;">
</div>
Add this in the section of header.php file:
<script type="text/javascript">
$(document).ready(function(){
$('#slider_mask').hide();
$('.anythingSlider').css({'display':'block'});
}
Add this to the CSS file:
.anythingSlider {display:none;}

Does Blueprint prevent a 100% background-size for images in CSS?

I'm trying to create a website with a background-size:100% 100% css rule. It's an image that sits behind the content and is designed in such a way that no matter the dimensions of the browser window it still works well.
I think the rule I have (as below) is clashing with Blueprint somehow.
body {
background:url('../img/bg.jpg') no-repeat;
background-size:100% 100%;
-moz-background-size:100% 100%;
-webkit-background-size:100% 100%;
}
This should generate a perfect 100% background image, however, the results I'm getting is that the background finishes where the content finishes, regardless of the browser window size.
Here are two images of what I want and what I'm getting:
EXPECTED
WHAT I'M GETTING (regardless of browser size)
Please help me, I'm not sure how to proceed with this.
Here is my HTML setup for the page:
<body>
<div class="container">
<div id="navbar" class="span-6 last">
<div id="logo" class="span-6 last"></div>
<div id="menu">
<ul>
<li class="menu-current">Home</li>
<li>About Us</li>
<li>Services</li>
<li>Contact Us</li>
</ul>
</div>
</div>
<div id="content" class="span-18 last">
</div>
</div>
</body>
If the container is 550px high then the background ends 550px down the page with an empty white space beneath that area.
I was able to replicate the effect on JSFiddle:
http://jsfiddle.net/danhanly/TurW5/4/
Would be nice if you can show us your HTML and CSS that way maybe I can pin point what your doing wrong.
You can write.
html {height:100%}
body {background:url('/image.jpg') no-repeat center}
#container {
margin:20px auto;
width:960px;
overflow:hidden}
Adding a min-height to the body that is equal to the height of the background-image will ensure that the body is large enough to display the entire background.