Landscape images taken from iPhone appear upside down on Desktop Chrome, but proper orientation on iPhone Safari. An example is the car on the homepage https://www.dapidi.com/#/
I doubt the problem is with the browsers or devices. After searching for an answer I came across this directive which seems to work most times, but not for the image of this car. I believe this should be a "solved problem" already, but I cannot seem to find an answer. Anyone have a solution how to solve this surely common dilemma?
DIRECTIVE
angular.module('myApp')
.directive('imgOrientation', function(){
return {
restrict: 'A',
link: function(scope, element/*, attrs*/) {
function setTransform(transform) {
element.css('-ms-transform', transform);
element.css('-webkit-transform', transform);
element.css('-moz-transform', transform);
element.css('transform', transform);
}
var parent = element.parent();
$(element).bind('load', function() {
EXIF.getData(element[0], function() {
var orientation = EXIF.getTag(element[0], 'Orientation');
var height = element.height();
var width = element.width();
if (orientation && orientation !== 1) {
switch (orientation) {
case 2:
setTransform('rotateY(180deg)');
break;
case 3:
setTransform('rotate(180deg)');
break;
case 4:
setTransform('rotateX(180deg)');
break;
case 5:
setTransform('rotateZ(90deg) rotateX(180deg)');
if (width > height) {
parent.css('height', width + 'px');
element.css('margin-top', ((width -height) / 2) + 'px');
}
break;
case 6:
setTransform('rotate(90deg)');
if (width > height) {
parent.css('height', width + 'px');
element.css('margin-top', ((width -height) / 2) + 'px');
}
break;
case 7:
setTransform('rotateZ(90deg) rotateY(180deg)');
if (width > height) {
parent.css('height', width + 'px');
element.css('margin-top', ((width -height) / 2) + 'px');
}
break;
case 8:
setTransform('rotate(-90deg)');
if (width > height) {
parent.css('height', width + 'px');
element.css('margin-top', ((width -height) / 2) + 'px');
}
break;
}
}
});
});
}
};
});
User error. I had a typo in the directive attribute name in the HTML.
Was: img-fix-orientation
Should have been: img-orientation
(face palm)
Forgot I had renamed it at some point.
The directive seems to work.
Related
I'm upgrading an application from Here Maps Javascript API v2 to v3.
In v2, the infobubbles re-position in the viewport so they stay on the screen (e.g. if it's on the left of the viewport, then the infobubble re-positions to the right so it doesn't appear off screen)
This behaviour no longer exists in v3 of the Here Maps JS API. The infobubble stays put all the time. I can't find any settings for this - is it possible to get this old behaviour back?
Cheers
I couldn't find any solution to this so rolled my own code to make it happen.
Here it is in case it helps anyone out ...
$(document).ready(function () {
setInterval(function () {
if ($('.H_ib_body').is(':visible')) {
var top = parseInt($('.H_ib_top').css('transform').split(',')[5]);
var left = parseInt($('.H_ib_top').css('transform').split(',')[4]);
var height = $('.H_ib_body').height();
if ($('.H_ib_body').attr('data-isBottom') != '1') { // on top
if (height - top > 0) {
{
$('.H_ib_body').css('bottom', 'auto').css('top', '0em').attr('data-isBottom', '1');
$('.H_ib_tail').css('transform', 'rotate(180deg)');
}
}
} else { // on bottom
var totalHeight = $('#map canvas').height();
if ((top + height) > totalHeight) {
$('.H_ib_body').css('bottom', '.5em').css('top', 'auto').attr('data-isBottom', '0');
$('.H_ib_tail').css('transform', '');
}
}
if ($('.H_ib_body').attr('data-isRight') != '1') { // on left
if (left - $('.H_ib_body').width() < -30) {
$('.H_ib_body').css('right', 'auto').css('left', '-20px').attr('data-isRight', '1');
}
} else { // on right
var totalWidth = $('#map canvas').width();
if (left + $('.H_ib_body').width() > totalWidth) {
$('.H_ib_body').css('right', '0px').css('left', 'auto').attr('data-isRight', '0');
}
}
}
}, 20);
});
I'm playing with CSS rotatations to get a kaleidoscope effect in CSS.
Everything seems good except with Chrome at some resolution (no issue on IE10, I didn't test FF)
I don't know why but sometime I have some weird white borders at the center of the kaleidoscope even if everything seems fine with the rotation values. I can't find any workaround...
You can test a working demo here : http://jsfiddle.net/Lvc0u55v/4519/
You'll probably need to move the slider from jsfiddle to see the white borders displayed.
I'm using this kind of css: transform: rotate(151deg) matrix(-1, 0, 0, 1, 0, 0) with a background image.
Could you help me to remove these borders?
Hope this will help.
var myApp = angular.module('myApp', []);
myApp.controller('mainCtrl', ['$scope', '$timeout',
function($scope, $timeout) {
$scope.bgImage = 'url(http://www.larousse.fr/encyclopedie/data/images/1310226-Vincent_Van_Gogh_la_Nuit_%C3%A9toil%C3%A9e.jpg)';
var section = 12;
$scope.getNumber = function() {
return new Array(section);
}
$scope.getRotation = function(i) {
var hasMatrix = false, deg = 0, base = 360 / section, rotation;
if (i % 2 === 0) {
i -= 1;
hasMatrix = true;
}
deg = Math.round(i * base + 1);
if (section <= 4) {
deg -= 1;
}
rotation = 'rotate(' + deg + 'deg)';
if (hasMatrix) {
// Please updated this line
rotation += ' matrix(-1, 0, 0, 1, -1, 0)';
}
return rotation;
}
$scope.mode = 'move';
$scope.onMousemove = function(e) {
console.log($scope.mode);
if ($scope.mode === 'move') {
$scope.bgPosition = e.pageX + 'px ' + e.pageY + 'px';
}
};
}]);
So, here is a custom directive to resize an element and it's contents based on a screen size change. I can see that the value of 'scalify' is changing how I would like it to, but the style itself is not changing. I know that the styles work when applied with static values directly in the css file.
.directive("card", function(){
return{
restrict : "E",
controller: function($scope, $element, $attrs){
var w = this;
window.onresize = function () {
$scope.scalify = {
'-ms-zoom': window.innerHeight/675,
'-moz-transform': 'scale(' + window.innerHeight/675 + ')',
'-o-transform': 'scale(' + window.innerHeight/675 + ')',
'-webkit-transform': 'scale(' + window.innerHeight/675 + ')'
};
$scope.$apply();
}
}
};
})
And here's how I use the ng-Style in the HTML
<card ng-style="scalify">
...
</card>
Hi please see here: http://run.plnkr.co/jfeF9NcPcGroNCsg/ probably you need to work a bit on your css transformation but style is changing when you change size of window as you wanted
app.directive("card", function($window) {
return {
restrict: "E",
link: function(scope, element, attrs) {
scope.onResizeFunction = function() {
//$scope.windowHeight = $window.innerHeight;
// $scope.windowWidth = $window.innerWidth;
var scalify = {
'-ms-zoom': $window.innerHeight / 675,
'-moz-transform': 'scale(' + $window.innerHeight / 675 + ')',
'-o-transform': 'scale(' + $window.innerHeight / 675 + ')',
'-webkit-transform': 'scale(' + $window.innerHeight / 675 + ')',
'background-color': 'red'
};
element.css(scalify);
console.log(element);
};
angular.element($window).bind('resize', function() {
scope.onResizeFunction();
scope.$apply();
});
}
}
});
I started the first question here: but it was very hard to make the effect for each single page I had, So I thought if I made the div that I wanted to make fixed not fixed to the screen scroll
Very Hard to compute heights with pure math and it doesn't work ultimately as you need to modify the calculation for every single page
Here is the code :
<script >window.addEventListener("scroll",function() {
if(window.scrollY >= 148) {
document.getElementById('main_nav').style.position = 'absolute';
document.getElementById('main_nav').style.bottom = '65%';
}
if(window.scrollY <= 148){
document.getElementById('main_nav').style.position = 'fixed';
document.getElementById('main_nav').style.top = '42%';
}
});</script>
so to get things clear That piece of code depends on scroll height of screen.
I need to apply the following effect :
when the page loads the main_nav div is position:fixed.
On scrolling down
when main_nav is above some div by: say 20px it should stop position:fixed.
It should stand still at it's last place.
On scrolling up again.
It should restore the position fixed again .
"This creates the float effect till some point"
Someone I know gave me the link for this question and a js code and told me to past it here
so here its if it is not relevant to the subject please let me knw
Someone I know gave me the link for this question and a js code and told me to past it here
so here its if it is not relevant to the subject please let me know and I will delete it
/* ===========================================================
* fixate.js v1
* Use:
* Inspired by the original jquery sticky scroller
* ========================================================== */
!function ($) {
"use strict"; // jshint ;_;
/* FIXATE PUBLIC CLASS DEFINITION
* =============================== */
var Fixate = function (element, options) {
this.init(element, options);
}
Fixate.prototype = {
constructor: Fixate
, init: function (element, options) {
var self, opts;
this.$element = $(element);
opts = this.options = this.getOptions(options);
this.zindex = this.$element.css('z-index');
this.$window = $(window);
this.$doc = $(document);
this.$bottomCap = opts.bottomCapEl ? $(opts.bottomCapEl) : false;
this.$topCap = opts.topCapEl ? $(opts.topCapEl) : false;
this.bottomOffset = opts.windowInset.bottom || 0;
this.topOffset = opts.windowInset.top || 0;
this.top = this.$element.offset().top - parseFloat(this.$element.css('margin-top').replace(/auto/, 0)) - this.topOffset;
this.eto = this.$element.offset().top;
this.origTop = this.$element.css('top');
this.origBottom = this.$element.css('bottom');
this.z = (this.zindex === '0' || this.zindex === 'auto') ? opts.zindex : this.zindex;
this.bh = (this.$bottomCap) ? this.$bottomCap.outerHeight(true) : 0;
self = this;
this.$window.on('scroll', function (e) {
self.fixate();
});
this.$doc.on('DOMNodeInserted DOMNodeRemoved', function(e){
//Called when elements are added or removed from DOM
self.fixate();
});
}
, getOptions: function (options) {
options = $.extend({}, $.fn['fixate'].defaults, options, this.$element.data());
return options;
}
, fixate: function(){
var s = this.$window.scrollTop()
, h = this.$element.outerHeight(true);
// Calc offset onscroll to get most updated results - incasse ajaxed els come in
this.bco = (this.$bottomCap) ? this.$bottomCap.offset().top : 0;
this.tco = (this.$topCap) ? this.$topCap.offset().top + this.$topCap.outerHeight(true) : 0;
this.dh = this.$doc.height();
if(this.options.windowEdge === 'top'){
this.fixToTop(s, h);
} else {
this.fixToBottom(s, h);
}
}
, fixToTop: function (s, h) {
var bco = this.bco
, to = this.topOffset
, eto = this.eto
, bo = this.bottomOffset
, point = bco - h - bo - to;
if (s >= this.top) {
this.$element.css({
'position': 'fixed',
'top': to,
'z-index': this.z
});
this.fixTouchDevice();
// Bottom cap calc -check cpu factor
if (s >= point) {
this.$element.css({
'top': Math.round(point - this.top + parseFloat(this.origTop)),
'position': 'absolute'
});
}
} else {
this.$element.css({
'position': '',
'top': this.origTop,
'z-index': this.zindex
});
}
}
, fixToBottom: function (s, h) {
var bco = this.bco
, to = this.topOffset
, eto = this.eto
, bo = this.bottomOffset;
if (s >= ( bco - h - bo - to - this.top) ) {
this.$element.css({
'bottom': Math.round(this.dh-(bco - bo)),
'position': 'absolute'
});
this.fixTouchDevice();
} else {
this.$element.css({
'position': 'fixed',
'bottom': bo,
'z-index': this.z
});
}
}
, fixTouchDevice: function(){
//stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
this.$element.css("position", "static");
}
}
}
/* FIXATE PLUGIN DEFINITION
* ========================= */
$.fn.fixate = function (option) {
return this.each(function () {
var $this = $(this),
data = $this.data('fixate'),
options = typeof option == 'object' && option;
if (!data) $this.data('fixate', (data = new Fixate(this, options)));
if (typeof option == 'string') data[option]();
})
}
$.fn.fixate.Constructor = Fixate;
$.fn.fixate.defaults = {
windowInset: {
top: 0,
bottom: 0
}
, windowEdge: 'top'
, bottomCapEl: 'footer'
, topCapEl: 'header'
, zindex: 5
};
}(window.jQuery);
I have an iframe that re-sizes its own content. The First time the iframe loades, the content re-sizes fine, but content not changing on subsequent resizing or page scrolling.
I have tried onresize,onmove...
<script type="text/javascript">
function autoIframe(frameId) {
try {
frame = document.getElementById(frameId);
innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
if (innerDoc == null) {
// Google Chrome
frame.height = document.all[frameId].clientHeight + document.all[frameId].offsetHeight + document.all[frameId].offsetTop;
}
else {
objToResize = (frame.style) ? frame.style : frame;
objToResize.height = (innerDoc.body.scrollHeight +200) + 'px';
//document.getElementById("autosizeframe").style.height=(innerDoc.body.scrollHeight+18)+'px';
//alert(frame.style.height+'-'+innerDoc.body.scrollHeight)
}
}
catch (err) {
document.getElementById("autosizeframe").style.height = '1600px';
document.getElementById("autosizeframe").style.width = '1000px';
//alert('Err: ' + err.message);
window.status = err.message;
}
}
I have made an iframe auto resizer script too, years ago. Maybe it is helpful for you:
http://www.professorweb.de/javascript-ajax/iframe-hohe-an-dessen-inhalt-automatisch-anpassen-v2.html