-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress Indicator overlap on small screens #382
Comments
I observed this problem as well, but wasn't sure how to address it. My main concern for fixing this is if things get odd when the screen size is extra large. |
Perhaps we can put the entire logo + loading bar in a |
@mattpen @jonathanolson or @zepumph can you please advise how to get the logo and progress indicator to scale together, and scale isometrically with the size of the window (as our sims do)? The document body currently contains these elements: <img id="splash" style="position: absolute;top: 45%;left: 50%;margin-left: -137px;margin-top: -65px;" src="{{PHET_SPLASH_DATA_URI}}">
<div id="progressBar"
style="position:absolute;top:50%;left:50%;margin-left:-147px;margin-top:50px;width:273px;height:10px">
<svg>
<rect id="progressBarBackground" x="10" y="10" width="273" height="10" rx="3" ry="3"
style="stroke: white;stroke-width:1"></rect>
<rect id="progressBarForeground" x="10" y="10" width="0" height="10" rx="3" ry="3" style="fill:#6acef5;"></rect>
</svg>
</div> |
Wrap with a div, use a CSS transform, and (unfortunately) duplicate code for isometric scaling? Although it's somewhat nice to have the logo larger when it is small, and not huge when the sim is in a large window. |
That's a fair point. Perhaps we should make this part of the design, and just move the progress bar to accommodate? |
My inclination is to have the entire sim be scaled (even the splash screen.) But perhaps it is a good question for @ariel-phet? |
@samreid it is seems the scaling everything isometrically (though in some cases not aesthetically perfect) is the most straightforward approach. So lets go with splash screen being scaled. |
I'm unsure about how I can help here. I'm not too familiar with scaling. Let me know if you want me to implement anything once we figure it out, or if you need anything at all from me. |
I tried this: <div id="splash-container" class="centered">
<img class="inner" id="splash">
<svg class="inner">
<rect id="progressBarBackground" x="10" y="10" width="273" height="10" rx="3" ry="3"
style="stroke: white;stroke-width:1"></rect>
<rect id="progressBarForeground" x="10" y="10" width="0" height="10" rx="3" ry="3" style="fill:#6acef5;"></rect>
</svg>
</div> with <style>
.centered {
position: fixed;
top: 50%;
left: 50%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
}
.inner {
position: absolute;
}
#splash-container{
}
</style> And it did not turn out too well. |
This has most of the logic we need: |
This is mostly working: <!DOCTYPE HTML>
<!-- Top-level HTML file for faradays-law generated by 'grunt generate-development-html' -->
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="initial-scale=1,user-scalable=no,maximum-scale=1"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="phet-sim-level" content="development">
<title>faradays-law</title>
<style>.hidden {
display: none
}</style>
</head>
<body bgcolor="black">
<!-- a11y - hidden until needed to prevent premature announcement -->
<div id='aria-live-elements' hidden
style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; clip: rect(0px 0px 0px 0px); pointer-events: none;">
<p id="assertive" aria-live="assertive" aria-atomic="true"></p>
<p id="polite" aria-live="polite" aria-atomic="true"></p>
<p id="assertive-alert" aria-live="assertive" role="alert" aria-atomic="true"></p>
<p id="polite-status" aria-live="polite" role="status" aria-atomic="true"></p>
</div>
<!--
Subtract off half the image width and height to center it.
Additionally, move the entire image up by a bit. This is done by changing the top margin to be lower than 50%
The logo dimensions are given in splash.svg, currently at width="273.172px" height="130.05px"
-->
<div id="splash-container" class="hidden">
<img id="splash">
<div id="progressBar" style="width:273px;height:10px">
<svg>
<rect id="progressBarBackground" x="0" y="10" width="273" height="10" rx="3" ry="3"
style="stroke: white;stroke-width:1"></rect>
<rect id="progressBarForeground" x="0" y="10" width="0" height="10" rx="3" ry="3" style="fill:#6acef5;"></rect>
</svg>
</div>
</div>
<script type="text/javascript">
function fillDiv( $div, proportional ) {
var currentWidth = $div.outerWidth();
var currentHeight = $div.outerHeight();
var availableHeight = window.innerHeight;
var availableWidth = window.innerWidth;
var scaleX = availableWidth / currentWidth;
var scaleY = availableHeight / currentHeight;
if ( proportional ) {
scaleX = Math.min( scaleX, scaleY );
scaleY = scaleX;
}
scaleX = scaleX / 4;
scaleY = scaleY / 4;
var translationX = Math.round( (availableWidth - (currentWidth * scaleX)) / 2 );
var translationY = Math.round( (availableHeight - (currentHeight * scaleY)) / 2 );
$div.css( {
"position": "fixed",
"left": "0px",
"top": "0px",
"-webkit-transform": "translate(" + translationX + "px, "
+ translationY + "px) scale3d("
+ scaleX + ", " + scaleY + ", 1)",
"-webkit-transform-origin": "0 0"
} );
// Show the splash screen after it has been positioned
$div.removeClass( 'hidden' );
}
function initialize() {
var div = $( '#splash-container' );
fillDiv( div, true );
if ( "onorientationchange" in window ) {
console.log( "Using orientationchange" );
// There seems to be a bug in some Android variants such that the
// metrics like innerHeight and outerHeight (used in fillDiv above)
// are not updated when the orientationEvent is triggered. The
// half-second delay gives the browser a chance to update the
// metrics before rescaling the div.
$( window ).bind( "orientationchange", function() { setTimeout( function() { fillDiv( div, true ); }, 500 ) } );
}
else if ( "ondeviceorientation" in window ) {
console.log( "Using deviceorientation" );
// Unlike the event above this not limited to a horzontal/vertical
// flip and will trigger for any device orientation movement
$( window ).bind( "deviceorientation", function() { setTimeout( function() { fillDiv( div, true ); }, 500 ) } );
}
else {
console.log( "No orientation supported, fallback to resize" );
$( window ).bind( "resize", function() { fillDiv( div, true ); } );
}
fillDiv( div, true );
}
window.addEventListener( 'load', initialize );
(function() {
// Identify the brand (assume generated brand if not provided with query parameters)
var brandMatch = location.search.match( /brand=([^&]+)/ );
var brand = brandMatch ? decodeURIComponent( brandMatch[ 1 ] ) : 'adapted-from-phet';
// Load the desired splash screen image
document.getElementById( 'splash' ).src = '../brand/' + brand + '/images/splash.svg';
// Preloads, with more included for phet-io brand
var preloads = ( brand === 'phet-io' ) ? [
'../sherpa/lib/jquery-2.1.0.js',
'../sherpa/lib/lodash-2.4.1.js',
'../sherpa/lib/FileSaver-b8054a2.js',
'../assert/js/assert.js',
'../query-string-machine/js/QueryStringMachine.js',
'../chipper/js/initialize-globals.js',
'../chipper/js/getVersionForBrand.js',
'../sherpa/lib/seedrandom-2.4.2.js',
'../sherpa/lib/game-up-camera-1.0.0.js',
'../sherpa/lib/base64-js-1.2.0.js',
'../sherpa/lib/TextEncoderLite-3c9f6f0.js',
'../sherpa/lib/Tween-r12.js',
'../sherpa/lib/jsondiffpatch-0.1.31.js'
] : [
'../sherpa/lib/jquery-2.1.0.js',
'../sherpa/lib/lodash-2.4.1.js',
'../sherpa/lib/FileSaver-b8054a2.js',
'../assert/js/assert.js',
'../query-string-machine/js/QueryStringMachine.js',
'../chipper/js/initialize-globals.js',
'../chipper/js/getVersionForBrand.js',
'../sherpa/lib/seedrandom-2.4.2.js',
'../sherpa/lib/game-up-camera-1.0.0.js',
'../sherpa/lib/base64-js-1.2.0.js',
'../sherpa/lib/TextEncoderLite-3c9f6f0.js',
'../sherpa/lib/Tween-r12.js'
];
// Loads a synchronously-executed asynchronously-downloaded script tag, with optional data-main parameter.
// See http://www.html5rocks.com/en/tutorials/speed/script-loading/ for more about script loading. It helps to
// load all of the scripts with this method, so they are treated the same (and placed in the correct execution
// order).
function loadURL( preloadURL, main ) {
var script = document.createElement( 'script' );
if ( typeof main === 'string' ) {
script.setAttribute( 'data-main', main );
}
script.type = 'text/javascript';
script.src = preloadURL;
script.async = false;
document.head.appendChild( script );
}
// Queue all of the preloads to be loaded.
preloads.forEach( loadURL );
loadURL( '../sherpa/lib/require-2.1.11.js', 'js/faradays-law-config.js' );
})();
</script>
</body>
</html> My main concerns:
|
This is a method we use a lot in the website, is this helpful? var interval = setInterval( function() {
if ( typeof $ !== 'undefined' ) {
$( document ).ready( function() {
launchFunctionHere();
} );
clearInterval( interval );
}
}, 100 ); |
I'm planning to write these few lines without jquery so it's not an issue. |
This splash.js is mostly working: // Copyright 2016, University of Colorado Boulder
/**
<!--
Subtract off half the image width and height to center it.
Additionally, move the entire image up by a bit. This is done by changing the top margin to be lower than 50%
The logo dimensions are given in splash.svg, currently at width='273.172px' height='130.05px'
-->
<div id='splash-container' class='hidden'>
<img id='splash'>
<div id='progressBar' style='width:273px;height:10px'>
<svg>
<rect id='progressBarBackground' x='0' y='10' width='273' height='10' rx='3' ry='3'
style='stroke: white;stroke-width:1'></rect>
<rect id='progressBarForeground' x='0' y='10' width='0' height='10' rx='3' ry='3' style='fill:#6acef5;'></rect>
</svg>
</div>
</div>
**/
(function() {
'use strict';
function centerDiv( div ) {
var currentWidth = 273;
var currentHeight = 130;
var availableHeight = window.innerHeight;
var availableWidth = window.innerWidth;
var scaleX = availableWidth / currentWidth;
var scaleY = availableHeight / currentHeight;
var scale = Math.min( scaleX, scaleY );
scaleX = scale;
scaleY = scale;
scaleX = scaleX / 3;
scaleY = scaleY / 3;
var translationX = Math.round( (availableWidth - (currentWidth * scaleX)) / 2 );
var translationY = Math.round( (availableHeight - (currentHeight * scaleY)) / 2 );
div.style.position = 'fixed';
div.style.left = '0px';
div.style.top = '0px';
div.style[ '-webkit-transform' ] = 'translate(' + translationX + 'px, ' + translationY + 'px) ' +
'scale3d(' + scaleX + ', ' + scaleY + ', 1)';
div.style[ '-webkit-transform-origin' ] = '0 0';
}
function initialize() {
var xmlns = 'http://www.w3.org/2000/svg';
var div = document.createElement( 'div' );
var splashImage = document.createElement( 'img' );
splashImage.style.display = 'block';
splashImage.setAttribute( 'id', 'splash' );
// Identify the brand (assume generated brand if not provided with query parameters)
var brandMatch = location.search.match( /brand=([^&]+)/ );
var brand = brandMatch ? decodeURIComponent( brandMatch[ 1 ] ) : 'adapted-from-phet';
// Wait until the image has loaded so that everything appears at once.
// Without this, the loading bar appears long before the splash image
splashImage.onload = function() {
// TODO: make sure the body did not already have such a div (if stored from Chrome=>save as or iOS Reading Mode).
document.body.appendChild( div );
};
var progressBarDiv = document.createElement( 'div' );
progressBarDiv.setAttribute( 'id', 'progressBar' );
progressBarDiv.setAttribute( 'style', 'width:273px;height:10px' );
progressBarDiv.style.display = 'block';
var svg = document.createElementNS( xmlns, 'svg' );
var progressBarBackground = document.createElementNS( xmlns, 'rect' );
progressBarBackground.setAttribute( 'id', 'progressBarBackground' );
progressBarBackground.setAttribute( 'x', '0' );
progressBarBackground.setAttribute( 'y', '10' );
progressBarBackground.setAttribute( 'width', '273' );
progressBarBackground.setAttribute( 'height', '10' );
progressBarBackground.setAttribute( 'rx', '3' );
progressBarBackground.setAttribute( 'ry', '3' );
progressBarBackground.setAttribute( 'style', 'stroke: white;stroke-width:1' );
var progressBarForeground = document.createElementNS( xmlns, 'rect' );
progressBarForeground.setAttribute( 'id', 'progressBarForeground' );
progressBarForeground.setAttribute( 'x', '0' );
progressBarForeground.setAttribute( 'y', '10' );
progressBarForeground.setAttribute( 'width', '0' );
progressBarForeground.setAttribute( 'height', '10' );
progressBarForeground.setAttribute( 'rx', '3' );
progressBarForeground.setAttribute( 'ry', '3' );
progressBarForeground.setAttribute( 'style', 'fill:#6acef5;' );
svg.appendChild( progressBarBackground );
svg.appendChild( progressBarForeground );
div.appendChild( splashImage );
div.appendChild( svg );
// Load the desired splash screen image
splashImage.src = '../brand/' + brand + '/images/splash.svg';
window.addEventListener( 'resize', function() {
centerDiv( div );
} );
centerDiv( div );
window.addEventListener( 'load', function() {
centerDiv( div );
} );
}
initialize();
})(); |
The PhET-iO logo had the wrong artwork bounds, after fixing that things are looking nice! Latest splash.js // Copyright 2016, University of Colorado Boulder
/**
<!--
Subtract off half the image width and height to center it.
Additionally, move the entire image up by a bit. This is done by changing the top margin to be lower than 50%
The logo dimensions are given in splash.svg, currently at width='273.172px' height='130.05px'
-->
<div id='splash-container' class='hidden'>
<img id='splash'>
<div id='progressBar' style='width:273px;height:10px'>
<svg>
<rect id='progressBarBackground' x='0' y='10' width='273' height='10' rx='3' ry='3'
style='stroke: white;stroke-width:1'></rect>
<rect id='progressBarForeground' x='0' y='10' width='0' height='10' rx='3' ry='3' style='fill:#6acef5;'></rect>
</svg>
</div>
</div>
**/
(function() {
'use strict';
function centerDiv( div, splashImg ) {
var currentWidth = splashImg.width;
var currentHeight = splashImg.height;
var availableHeight = window.innerHeight;
var availableWidth = window.innerWidth;
var scaleX = availableWidth / currentWidth;
var scaleY = availableHeight / currentHeight;
var scale = Math.min( scaleX, scaleY );
scaleX = scale;
scaleY = scale;
scaleX = scaleX / 3;
scaleY = scaleY / 3;
var translationX = Math.round( (availableWidth - (currentWidth * scaleX)) / 2 );
var translationY = Math.round( (availableHeight - (currentHeight * scaleY)) / 2 );
div.style.position = 'fixed';
div.style.left = '0px';
div.style.top = '0px';
div.style[ '-webkit-transform' ] = 'translate(' + translationX + 'px, ' + translationY + 'px) ' +
'scale3d(' + scaleX + ', ' + scaleY + ', 1)';
div.style[ '-webkit-transform-origin' ] = '0 0';
}
function initialize() {
var xmlns = 'http://www.w3.org/2000/svg';
var div = document.createElement( 'div' );
var splashImage = document.createElement( 'img' );
splashImage.style.display = 'block';
splashImage.setAttribute( 'id', 'splash' );
window.hellothere = splashImage;
// Identify the brand (assume generated brand if not provided with query parameters)
var brandMatch = location.search.match( /brand=([^&]+)/ );
var brand = brandMatch ? decodeURIComponent( brandMatch[ 1 ] ) : 'adapted-from-phet';
// Wait until the image has loaded so that everything appears at once.
// Without this, the loading bar appears long before the splash image
splashImage.onload = function() {
centerDiv( div, splashImage );
// TODO: make sure the body did not already have such a div (if stored from Chrome=>save as or iOS Reading Mode).
document.body.appendChild( div );
window.addEventListener( 'resize', function() {
centerDiv( div, splashImage );
} );
window.addEventListener( 'load', function() {
centerDiv( div, splashImage );
} );
};
var progressBarDiv = document.createElement( 'div' );
progressBarDiv.setAttribute( 'id', 'progressBar' );
progressBarDiv.setAttribute( 'style', 'width:273px;height:10px' );
progressBarDiv.style.display = 'block';
var svg = document.createElementNS( xmlns, 'svg' );
var progressBarBackground = document.createElementNS( xmlns, 'rect' );
progressBarBackground.setAttribute( 'id', 'progressBarBackground' );
progressBarBackground.setAttribute( 'x', '0' );
progressBarBackground.setAttribute( 'y', '10' );
progressBarBackground.setAttribute( 'width', '273' );
progressBarBackground.setAttribute( 'height', '10' );
progressBarBackground.setAttribute( 'rx', '3' );
progressBarBackground.setAttribute( 'ry', '3' );
progressBarBackground.setAttribute( 'style', 'stroke: white;stroke-width:1' );
var progressBarForeground = document.createElementNS( xmlns, 'rect' );
progressBarForeground.setAttribute( 'id', 'progressBarForeground' );
progressBarForeground.setAttribute( 'x', '0' );
progressBarForeground.setAttribute( 'y', '10' );
progressBarForeground.setAttribute( 'width', '0' );
progressBarForeground.setAttribute( 'height', '10' );
progressBarForeground.setAttribute( 'rx', '3' );
progressBarForeground.setAttribute( 'ry', '3' );
progressBarForeground.setAttribute( 'style', 'fill:#6acef5;' );
svg.appendChild( progressBarBackground );
svg.appendChild( progressBarForeground );
div.appendChild( splashImage );
div.appendChild( svg );
// Load the desired splash screen image
splashImage.src = '../brand/' + brand + '/images/splash.svg';
}
initialize();
})(); |
We will need to test this new implementation on many platforms, so we will probably need to create branches for chipper and joist. Other steps to complete before testing:
Questions for testing:
After testing:
|
@samreid do you want to create a review issue and assign it to JO? |
Review will happen in #392. After that's complete, we can finish with the last checkboxes in #382 (comment) |
On hold while we await review. |
Remaining work:
Questions for testing:
After testing:
|
@ariel-phet I published http://www.colorado.edu/physics/phet/dev/html/faradays-law/1.3.7-dev.3/faradays-law_en.html which demonstrates the resizing splash screen. I chose a scaling factor that matched the size on my screen--people that have a bigger screen than me will see a bigger splash logo than they used to. People that have a smaller screen than me will see a smaller splash logo than they used to. Can you please review this version and see if the size seems right to you? Try resizing your browser and make sure it seems good for a variety of sizes. After you've checked it out, we can send it to the QA team for cross-platform testing and checking for rendering issues. |
@samreid looks good to me! |
On hold until the preceding issue is complete. |
OK I merged master to splash-script for joist and chipper, so I can investigate further. |
On hold until we discuss IE in #408 |
All of these are using http://www.colorado.edu/physics/phet/dev/html/energy-skate-park-basics/1.3.1-dev.6/energy-skate-park-basics_en.html. @samreid this is in a 300x200 iframe: Is this an issue anymore? |
Looks good to me, closing. |
It seems when the screen is small enough, we get some overlap on the phet-io logo (because the logo is farther down on the screen:
The text was updated successfully, but these errors were encountered: