Two serial webkit transitions does not work on some android devices - javascript

I want to have two webkitTransitions applied one after one to the same div element for webkitTransform property. Here is the code:
<html>
<head>
<title></title>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", init);
function init() {
var d1 = document.getElementById("d1");
d1.style.webkitTransition = "-webkit-transform 1s linear";
d1.style.webkitTransform = "translate(-100px,0px)";
setTimeout(function(){
d1.style.webkitTransition = "-webkit-transform 1s linear";
d1.style.webkitTransform = "translate(-150px,0px)";
}, 1500);
}
</script>
<style type="text/css">
div#d1 {
position: absolute;
background-color: rgba(13,15,112,122);
width: 200px;
height: 200px;
overflow: hidden;
}
</style>
</head>
<body>
<div id="d1"/>
</body>
</html>
http://bit.ly/UnTqAV
This results to the second transform is applied directly without any transition on Android 4.0.4 Samsung tablets default browser (GT-P5110 GT-P3110 ...). Other devices work fine.
I've tried using with/without 3d postfix and open GL switched on/off. Does anyone have the same experience?

We had the same problem, it's a (big) bug of Android 4.0.4 WebView. We had to write again some animations on our webapp.
The trick is to use the CSS matrix property for every transformation, instead of the specific translate, scale, and so on.
This link is very nice to learn more on 2D matrices:
http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/matrix2dExplorer.html

Related

Start Animation (Animate CC) only when the canvas become visible after scrolling.

I have an animation (made with Adobe animate CC) that I have included into my html file. I am trying to change its original script in order to start the animation from the beginning only when it becomes visible in the viewport of the browser. Unfortunately, I searched widely but couldn't make any of the solutions I found worked for my case.
This is the original code I'm trying to change:
<html>
<head>
<script>
var canvas, stage, exportRoot, anim_container, dom_overlay_container,
fnStartAnimation;
function init() {
canvas = document.getElementById("canvas");
anim_container = document.getElementById("animation_container");
dom_overlay_container = document.getElementById("dom_overlay_container");
var comp=AdobeAn.getComposition("07578064E5C140B781D146A1AE4968A3");
var lib=comp.getLibrary();
handleComplete({},comp);
}
function handleComplete(evt,comp) {
//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
var lib=comp.getLibrary();
var ss=comp.getSpriteSheet();
exportRoot = new lib.Water_illustrazione_revista_scrollplay();
stage = new lib.Stage(canvas);
//Registers the "tick" event listener.
fnStartAnimation = function() {
stage.addChild(exportRoot);
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
}
//follow a code to support hidpi screens and responsive scaling.
</script>
</head>
<body onload="init();" style="margin:0px;">
<div id="anchor5" class="Anime_p">
<div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:1280px; height:700px">
<canvas id="canvas" width="1280" height="700" style="position: absolute; display: block; background-color:rgba(255, 255, 255, 1.00);"></canvas>
<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:1280px; height:700px; position: absolute; left: 0px; top: 0px; display: block;">
</div>
</div>
</div>
</body>
</html>
You simply need to export the animation as stopped at first and then check when the div comes in browser view. Whenever it does, start the animation.
Add exportRoot.stop(); in the end of fnStartAnimation();
Check for visibility of your animation div in browser as explained here - How to tell if a DOM element is visible in the current viewport?
Whenever the condition is satisfied, add the code - exportRoot.play();

centering videojs vertically on a page?

Context: Electron desktop app using Timeline.js which is embedding Video.js through an iFrame. The iFrame source is below.
I've been struggling with this for a few hours now: I need to vertically center the Video.js instance in the iFrame it is within. I can't hardcode values because the app (not only videojs) can go full screen.
Using the "brute force" CSS below, it "works" but obviously the black bars are not acceptable. I removed that an added a ref to the vjs vjs-16-9 CSS and it works great: sets up size based on content, resizes in full screen mode – all good except that I haven't been able to figure out how to center the vjs instance vertically in the iFrame.
Probably something simple but I'm new at all this.
.video-js {
position: absolute;
top: 0;
left: 0;
width: 100%!important;
height: 100%!important;
}
Using vjs-16-9 CSS
iFrame source
<!DOCTYPE html>
<html lang="en">
<head>
<title>Video.JS Example</title>
<link href="../node_modules/video.js/dist/video-js.min.css" rel="stylesheet">
<script src="../node_modules/video.js/dist/video.min.js"></script>
<style>
html, body {
height:100%;
width:100%;
padding: 0px;
margin: 0px;
}
</style>
</head>
<body>
<div>
<video id="videoPlayer" class="video-js vjs-default-skin vjs-16-9" controls preload="auto">
</video>
</div>
<script>
function getParamValue(paramName) {
var url = window.location.search.substring(1);
var qArray = url.split('&');
for (var i = 0; i < qArray.length; i++) {
var pArr = qArray[i].split('=');
if (pArr[0] == paramName)
return pArr[1];
}
}
// grap the video & poster frame refs from url
var videoSrc = getParamValue('videoSrc');
videoSrc = "assets/videos/" + videoSrc;
var poster = getParamValue('poster');
poster = "assets/images/" + poster;
videojs("videoPlayer", {}, function () {
this.src(videoSrc);
this.poster(poster);
this.load();
});
</script>
</body>
</html>
Finally found a solution which doesn't seem fragile: Vertical align anything with just 3 lines of CSS.
Assigned to the div containing the videojs instance
.centerVertically {
position: relative;
top: 50%;
transform: translateY(-50%);
}
<div class="centerVertically">
<video id="videoPlayer" class="video-js vjs-default-skin vjs-16-9" controls preload="auto">
</video>
</div>
Most likely , iframe has its own styling by its own. Hence , brute force Css is needed. But to answer your question regarding aligning center for your iframe. You might want to explore more on using flex , justify content, justify center.
There are also other alternative such as using float but float is not a good practice to use unless you really have no choice of using it. The reason is. Float might react differently and mess up the alignment at certain occasions ..
I hope my information helps.
Cheers.

Controlling image height in Bootstrap-Lightbox gallery

I'm working on a website of an artist, so galleries are really important. I'm using Bootstrap for the website, and Lightbox for Bootstrap plugin for the galleries. It works fine adjusting the width of the image to any resolution (I want to make it as responsive as possible). But, as you can observe if you click on any vertical photo (for example, the one in the second row, second column), when it opens, it's bigger than the screen and it can't be seen without scrolling.
So, I want to get rid of this problem, adjusting the maximum height of the image to the height of the screen. But I can't find the way to do this. Any ideas for doing it in a simple way? I've uploaded the website to a server so you can see the problem: http://mural.uv.es/ivape2/es/galeria.html
Thank you.
I had a similar problem and tinny77's answer was the only thing that approached a solution.
Here is a working snippet of what I ended up with
$().ready(function() {
$('[data-toggle="lightbox"]').click(function(event) {
event.preventDefault();
$(this).ekkoLightbox({
type: 'image',
onContentLoaded: function() {
var container = $('.ekko-lightbox-container');
var image = container.find('img');
var windowHeight = $(window).height();
if(image.height() + 200 > windowHeight) {
image.css('height', windowHeight - 150);
var dialog = container.parents('.modal-dialog');
var padding = parseInt(dialog.find('.modal-body').css('padding'));
dialog.css('max-width', image.width() + padding * 2 + 2);
}
}
});
});
});
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js" type="text/javascript"></script>
<script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/3.3.0/ekko-lightbox.min.js"></script>
</head>
<body>
<p>Click Image</p>
<a href="http://lorempixel.com/400/1920" data-toggle="lightbox">
<img height="200" src="http://lorempixel.com/400/1920"/>
</a>
</body>
</html>
I solved it this way by editing the Javascript:
onContentLoaded: function() {
var imgh = $(".ekko-lightbox-container").find("img").height();
var winh = $(window).height();
if ((imgh+200)>winh)
{
$(".ekko-lightbox-container").find("img").css("height",winh-150).css("width","auto").css("margin","0 auto");
}
}
See the JSFiddle
.container {
height:100%;
width: 100%;
border: 1px solid #000000;
}
.item {
max-height: 90%;
max-width: 90%;
border: 1px solid #000000;
}
Assuming you have a .container width a given width/height. I've put both width and height at 100% for the .container
Then you just create a class and asign it max-width: 80%; which will output the image to be 80% the width of the .container
Try adding this
.ekko-lightbox.modal.fade.in div.modal-dialog{
max-width:27%;
}
This is just simple solution, best it will be to make media-queries for different resolution
This has been solved (commit on github) by calculating the maximum image height (80% of viewport height) in the preload function but currently it is not part of the base branch.

Liquid Layout IE Problems, of course (Newbie)

I'm new to CSS, never created a layout before and I'm having some issues with my first one in Internet Explorer. I think it looks good in Firefox though.
I have done a lot of reading about HTML and CSS before starting the layout so I knew IE had some bugs but even after making the layout and researching the issues none of the resolutions seem to be working. Im hoping someone here can help.
TL;DR: New layout not working in IE, need help(did research)
Problem 1: In IE the 2 right sidebars are too wide compared to Firefox. Everything else appears normal, just those 2 are too wide which is affecting the layout
Problem 2: When the window width is below 1024 it is supposed to switch from container1.css to container2.css effectively changing the container properties to better display in smaller resolutions. Works great in Firefox, but in IE it seems to remove the container period leaving the contents to flow throughout the entire window.
<HTML>
<HEAD>
<TITLE>My Liquid Layout</TITLE>
<link rel="stylesheet" type="text/css" href="LiquidLayout.css" />
<link id="container1" rel="stylesheet" type="text/css" href="container1.css" />
<link id="container2" rel="alternate" type="text/css" href="container2.css" />
<script type="text/javascript">
<!--
var css = "container1";
function changeStyle(styleSheet)
{
if(styleSheet == css)
return;
var selected = document.getElementById(styleSheet);
var current = document.getElementById(css);
if(!selected)
{
selected = current.cloneNode(true);
selected.id=styleSheet;
selected.setAttribute("href",current.getAttribute("href").replace(new
RegExp(css),styleSheet));
}
current.setAttribute("rel","stylesheet1");
selected.setAttribute("rel","stylesheet");
document.getElementsByTagName('head')[0].appendChild(selected);
css = styleSheet;
}
function windowSize()
{
var windowWidth;
var windowHeight;
windowWidth = window.innerWidth;
windowHeight = window.innerHeight;
if (document.body && document.body.offsetWidth)
{
windowWidth = document.body.offsetWidth;
windowHeight = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth )
{
windowWidth = document.documentElement.offsetWidth;
windowHeight = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight)
{
windowWidth = window.innerWidth;
windowHeight= window.innerHeight;
}
if(windowWidth < 1024)
changeStyle('container2');
else if(windowWidth >= 1024)
changeStyle('container1');
}
window.onresize = new Function("windowSize()");
//-->
</script>
</HEAD>
<BODY>
<div id = "container">
<div id = "header"><p id = "size"></p></div>
<div id = "content">
<div id = "menu">
<ul>
<li>About</li>
<li>Contact</li>
<li>Home</li>
<li>Video</li>
<li>Gallery</li>
<li>IGN</li>
</ul>
</div>
<div id = "sidebox"></div>
<div class = "column" id = "sidebar"></div>
<div class = "column" id = "main"></div>
</div>
<div id = "footer"></div>
</div>
</BODY>
</HTML>
The main CSS is:
body
{
background-color:gray;
margin: 0px;
text-align: center;
}
#header
{
width: 100%;
height: 200px;
background-color: yellow;
}
#content
{
padding-top:5px;
padding-bottom:0px;
padding-right:5px;
padding-left:5px;
min-height: 768px;
}
#menu
{
width: 66%;
height: 250px;
background-color: blue;
float: left;
}
#sidebox
{
width: 34%;
height: 250px;
background-color: red;
float: right;
display: inline;
}
#sidebar
{
width: 34%;
background-color: red;
height: 100%;
float: right;
}
#main
{
width: 65%;
height: 100%;
background-color: green;
float: left;
}
If anyone can please offer some advice on fixing these issues in IE I would appreciate it!
Any suggestions for improvement are welcome as well
You didn't specify which version of IE, so I'm guessing you've only checked the most recent version?
Add a doctype as suggested, and you should be ok in IE9, but if you're supporting other versions of IE as well you are going to want some way of targeting each version independently as they all have different and progressively worse bugs. Occasionally, something will work in IE7 but not IE8, but generally as you head towards IE6 your problems will multiply exponentially, especially with a liquid layout.
I'd recommend using Modernizr, which will add different class names to the HTML element depending on the version of IE in use. It also does a bunch of other stuff like making HTML5 elements styleable in older IE as well, so it is worth using, even without any of the other feature tests it offers. I can see you aren't using any HTML5 elements, but I don't know if that's your whole layout, or just the beginnings of it...
You'll probably also want to use Selectivizr so that most useful CSS3 features can be used in IE8 and below as well, although you need to use a JS library, such as jQuery for this, so it may or may not be useful. There isn't any CSS3 in your CSS, but again, your example could be much simplified
In terms of improvements to your code, you don't need to include HTML comments in your script tags <!-- and haven't since the days of like IE4 or something. Additionally, your should go at the bottom of the <body> (just before the closing </body>) for performance reasons, rather than in the <head>, and if you use the HTML5 doctype (which you can still use even if you aren't planning on using any HTML5 elements) you don't need to specify a type attribute on the <script> element. In JavaScript, the opening curly brackets should go on the same line as the function definition or conditional, so do:
if (condition) {
or:
function something() {
and not:
if (condition)
{
or:
function something()
{
This is usually ok most of the time, but it can produce bugs that are very hard to spot, so it is worth getting into the habit of doing it all the time. And when attaching an event listener, you don't need to specify new Function("function_name"), you can just attach the function directly:
window.onresize = windowSize();
Also, in CSS, zero values do not need to specify measurement units, so you can just have 0 instead of 0px...
If you have copy and pasted the entirity then your missing a doctype making IE render in quirksmode.
I would suggest adding the HTML5 doctype to the top of your document <!DOCTYPE html>
More information on quirks mode can be found here

jQuery UI (RAD/GUI) form designer

Well, I'm working on a visual form designer and decided to use jQuery UI as both the end form widgetset as well as the widgetset for the designer itself.
My main concern is to make jQuery wigets "read-only". I've had the following idea:
<style type="text/css">
.widget-wrap { position: relative; }
.widget-overlay { position: absolute; left:0; right:0; top:0; bottom:0; /*maybe z-index as well*/ }
</style>
<div class="widget-wrap" id="wdt1">
<button class="jquery-widget">Hello World!</button>
<div class="widget-overlay"><!----></div>
</div>
<script type="text/javascript">
$(function() {
$("button.jquery-widget").button();
});
function widgetLock(){
$("#wdt1 .widget-overlay").show();
}
function widgetRelease(){
$("#wdt1 .widget-overlay").hide();
}
</script>
Hope my example makes sense :)
My questions are;
does this sound good to you?
do you know of a better or another way?
do you see any possible issues with it?
I would say this is a very bad idea in that 1) you may find the overlay in a weird place in certain browser resolutions etc and 2) you can still tab to the item.
Much better to either;
Hide the element
Disable the element
Replace text boxes with labels, buttons with graphics etc.
Disable the click on the button
edit
You can use jQuery to unbind events on elements and then you can re-bind them later on.
If I was to build a form designer I'd make all elements divs with an image of the actual widget as a css background image, that way you can drag the widget representation around the form without activating it or having any of the overlay problems.
If you really wanted to make it look like the finished product you can have the actual widget nested inside the div but invisible when the users mouse is within the div, when the user moves the mouse out of the div then set the widget visible again.
DC
Yes I was aware that the background image would look wrong when stretched. So I thought about it on the way home. A better technique would be to create a widget sandwich
place the widget between 2 divs the bottom div controls the size and position the top prevents the widget from activating
<html>
<head>
<script language="JavaScript" type="text/JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script language="JavaScript" type="text/JavaScript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<style type="text/css">
<!--
.widget {
height: 100%;
width: 100%;
}
.widget_overlay {
border: thin solid #FF0000;
position: absolute;
top: 1px;
left: 1px;
right: 1px;
bottom: 1px;
right: 1px;
visibility:visible
}
.sz_controller {
position:absolute;
width:365px;
height:61px;
left: 142px;
top: 75px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
function ShowHide(button,id){
elem = document.getElementById(id)
if (elem.style.visibility=='hidden') {
elem.style.visibility='visible';
button.value="Hide Overlay";
} else {
elem.style.visibility = 'hidden';
button.value="Show Overlay";
}
}
</script>
</head>
<body>
<input type="button" name="Button" value="Hide Overlay" onClick="ShowHide(this,'widget_overlay')">
<div id="draggable" class="sz_controller" style=""><select class="widget" name="test">
<option>test 1</option>
<option>test 2</option>
<option>test 3</option>
</select><div id="widget_overlay" class="widget_overlay"></div></div>
<script>
$(function() {
$( "#draggable" ).draggable();
});
</script>
</body>
</html>
The above will work in firefox
Clicking the button hides the overlay div allowing testing of the widget, You can drag the object around the screen, no resizing logic has been implemented.
DC

Categories