UI Alignment Issue - css

Hope after so many tries I will get some pointers over here for issue i am facing.
As per above image, I need to have an POI in center of page(round circle in the image) and when I click on POI; I would like to open a pop up window in four position at shown in the image above with different css classes. Problem is that popup height can not be fixed and should be auto and that is where its tricky to handle the margin if I would like to achieve above UI.
Issues:
any pointers on positioning the popup with css classes as per images shown.
I have setup a fiddle here including popup and POI.
HTML:
<div id="follow-hotspot" class="hotspot-wrapper">
<img width="20px" heigh="20px" class="hotspot" src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-contact-512.png"/>
<div id="follow-textbox" class="textbox_hotspot hide" data-video="true">
<h1>Header</h1>
<p>
<b>Follow me</b> to see the css video
</p>
<iframe id="follow_video" width="230" height="150" src="https://www.youtube.com/embed/9YffrCViTVk" frameborder="0" id = "Overlayvideo" allow="accelerometer; autoplay *; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
JavaScript:
Let me know if any details are required. Any pointer how to achieve is ample enough; I am not expecting you to write code for me. How would I go about the implementation is all I am expecting.
//annonymous function
var poi = document.getElementById("follow-hotspot");
var popup = document.getElementById("follow-textbox");
poi.onclick = function() {
//alert("clicked");
if (popup.classList.contains('hide')) {
popup.classList.remove('hide');
popup.classList.add('show');
}
else if (popup.classList.contains('show')) {
popup.classList.remove('show');
popup.classList.add('hide');
videoEle = document.getElementById('follow_video');
videoEle.src = videoEle.src;
}
};
CSS:
Please refer to the fiddle for css.

I used translate property to give position to these content blocks and used percentage as units.I checked the output on changing the height and width of the content and still the position remained intact.
Glimpse of the output(->its The output)
var point_er = document.getElementsByClassName('pointer')[0];
var win_dow = document.getElementsByClassName('window');
var count = 0;
point_er.onclick = function() {
if (count % 2 == 0) {
for (var i = 0; i < win_dow.length; i++) {
win_dow[i].style.height = "250px";
win_dow[i].style.width = "300px";
}
win_dow[2].style.height = "300px";
win_dow[3].style.width = "400px";
} else {
for (var i = 0; i < win_dow.length; i++) {
win_dow[i].style.height = "0px";
win_dow[i].style.width = "0px";
}
}
count++;
}
* {
margin: 0px;
padding: 0px;
}
body {
height: 2400px;
}
.main {
width: 100%;
height: 100vh;
}
.window_main {}
.window {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 0px;
height: 0px;
border: 2px solid black;
}
.window:nth-child(1) {
transform-origin: 100% 100%;
transform: translate(-105%, -105%);
transition: 0.4s;
}
.window:nth-child(2) {
transform-origin: 0 100%;
transform: translate(5%, -105%);
transition: 0.5s;
}
.window:nth-child(3) {
transform-origin: 100% 0;
transform: translate(-105%, 5%);
transition: 0.6s;
}
.window:nth-child(4) {
transform-origin: 0% 0%;
transform: translate(5%, 5%);
transition: 0.7s;
}
.pointer {
text-decoration: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
height: 50px;
width: 50px;
background-color: #8B8AFF;
cursor: pointer;
transition: 0.4s;
}
.pointer:hover {
background-color: #6D6DE8
}
<div class="main">
<div class="window">1</div>
<div class="window">2</div>
<div class="window">3</div>
<div class="window">4</div>
</div>

Related

add transition effect in vue on backgroundImage

I've been searching for a couple of days to add a fade transition effect on the backgroundImage that I'm changing through a Vue app.
Here is the code snippet I've been testing on:
new Vue({
el: "#main",
data: {
images: [
"https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg",
"https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg",
"https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg"
],
current: 0,
show: false
},
methods: {
changeBG: function () {
if (this.current < this.images.length - 1) {
this.current = this.current + 1;
} else {
this.current = 0;
}
}
}
});
.main {
height: 800px;
width: 100%;
margin-left: auto;
margin-right: auto;
z-index: 0;
background-repeat: no-repeat;
background-size: cover;
background-position: center 0px;
}
button {
width: 200px;
height: 25px;
margin: 10px;
}
p.hello{
color: white;
margin: 10px;
font-size: 50px;
}
.fade-enter-active,
.fade-leave-active {
transition: all 2s linear;
}
.fade-enter-to,
.fade-leave {
opacity: 0;
}
.fade-enter,
.fade-leave-to {
opacity: 1;
}
/* hello example transition */
.slide-fade-enter-active {
transition: all 1s ease;
}
.slide-fade-leave-active {
transition: all 1s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
transform: translateX(10px);
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<transition name="fade">
<div v-if="changeBG" class="main" id="main" :style="{ backgroundImage: 'url(\'' + images[current] + '\')' }">
<button v-on:click="changeBG">
changeBG
</button>
<div id="testFromGuide">
<button #click="show = !show">
toggleHello
</button>
<transition name="slide-fade">
<p class="hello" v-if="show">all your base are belong to us</p>
</transition>
</div>
</div>
</transition>
My first question if this is simply possible? The reason I'm using backgroundImage is because the website I'm using this on has a background that is most easy to handle responsively through this (always covering, no repeat and keeping it center). And my scond question would be, if not, is there a possibility to make it work with a background set as described here?
In the codepen I've added an example of the vue guide to make sure it works and nothing is else is wrong. And the example works perfectly. Can't seem to find the answer for my example but I've been beginning to suspect it is simply not possible or I can't seem to find why vue isn't detecting something is changing.
For Vue Transitions to work, you need to change the DOM elements. So this way would work if you were changing actual images out. In your example, you're only changing an attribute value. The DOM doesn't trigger a transition since its the same element.
However, you can use the :key attribute to convince VUE to replace the element thus giving you a transition between 2 elements.
You can also set the image with inline CSS like you're doing in the example. You'll still have to create the transition in your CSS.
Here's an example using Vue Transition
new Vue({
el: "#main",
data: {
currentID: 0,
images: [
'https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg',
'https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg',
'https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg'
]
},
methods: {
toggleImage: function(){
if(this.currentID < this.images.length-1){
this.currentID +=1
} else {
this.currentID = 0
}
}
}
});
body {
overflow: hidden;
}
.main {
position: relative;
}
img {
width: 100%;
height: auto;
display: block;
position: absolute;
-webkit-transition: all 3s ease;
transition: all 3s ease;
}
button {
z-index: 100;
position: relative;
width: 200px;
height: 25px;
margin: 20px;
}
/* prefix with transition name */
.slide-fade-enter-active {
opacity: 1;
z-index: 10;
}
.slide-fade-leave-active {
opacity: 1;
}
.slide-fade-enter,
.slide-fade-leave-to {
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<div class="main" id="main">
<transition name="slide-fade">
<!-- SRC comes from the array of images the :key is important for vue to believe its a 'new' DOM element and do the transition -->
<img v-bind:src="images[currentID]" v-bind:key="currentID" />
</transition>
<button #click="toggleImage">
Toggle Image
</button>
</div>
However, you don't get a lot of control over that since it uses image tags. Instead, it might be better to use a background image like this:
new Vue({
el: "#main",
data: {
currentID: 0,
images: [
'https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg',
'https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg',
'https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg'
]
},
methods: {
toggleImage: function(){
if(this.currentID < this.images.length-1){
this.currentID +=1
} else {
this.currentID = 0
}
}
}
});
.main {
/* make this the size of the window */
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.theImage {
width: 100%;
height: 100%;
position: absolute;
background-color: #333;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
-webkit-transition: all 3s ease;
transition: all 3s ease;
}
button {
z-index: 100;
position: relative;
width: 200px;
height: 25px;
margin: 20px;
}
/* prefix with transition name */
.slide-fade-enter-active {
opacity: 1;
z-index: 10;
}
.slide-fade-leave-active {
opacity: 1;
}
.slide-fade-enter,
.slide-fade-leave-to {
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<div class="main" id="main">
<transition name="slide-fade">
<!-- SRC comes from the array of images the :key is important for vue to believe its a 'new' DOM element and do the transition -->
<div class="theImage" v-bind:style="{'background-image': 'url(' + images[currentID] + ')'}" v-bind:key="currentID"></div>
</transition>
<button #click="toggleImage">
Toggle Image
</button>
</div>
The answer was indeed to forget about vue transitions and let css do the work. A working example can be found here:
new Vue({
el: "#main",
data: {
show: false,
BG1: true,
BG2: false,
BG3: false
},
methods: {
changeBG: function(){
if (this.BG1 == true){
this.BG1 = false;
this.BG2 = true;
this.BG3 = false;
} else if (this.BG2 == true) {
this.BG1 = false;
this.BG2 = false;
this.BG3 = true;
} else if (this.BG3 == true) {
this.BG1 = true;
this.BG2 = false;
this.BG3 = false;
}
},
showBG1: function(){
if (this.BG1 == true){
return "";
} else {
return "transparent";
}
},
showBG2: function(){
if (this.BG2 == true){
return "";
} else {
return "transparent";
}
},
showBG3: function(){
if (this.BG3 == true){
return "";
} else {
return "transparent";
}
}
}
});
.main {
}
#bgs img.transparent {
opacity:0;
transform: translateY(-0.0px);
}
#bgs img{
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
z-index: -1;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
#media screen and (max-width: 1024px) { /* Specific to this particular image */
#bgs img{
left: 50%;
margin-left: -512px; /* 50% */
}
}
button {
z-index: 100;
position: relative;
width: 200px;
height: 25px;
margin: 20px;
}
p.hello{
color: white;
margin: 40px;
font-size: 50px;
}
.fade-enter-active {
transition: all 1s ease;
}
.fade-leave-active {
transition: all 1s ease;
}
.fade-enter, .fade-leave-to{
transform: translateY(-5px);
opacity: 0;
}
/* hello example transition */
.slide-fade-enter-active {
transition: all 1s ease;
}
.slide-fade-leave-active {
transition: all 1s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
transform: translateY(-5px);
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<div class="main" id="main">
<div id="bgs">
<img :class="showBG1()" src="https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg">
<img :class="showBG2()" src="https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg">
<img :class="showBG3()" src="https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg">
</div>
<button #click="changeBG">
changeBG
</button>
<div id="testFromGuide">
<button #click="show = !show">
toggleHello
</button>
<transition name="slide-fade">
<p class="hello" v-if="show">all your base are belong to us</p>
</transition>
</div>
</div>
It's not perfect yet as for every extra background I need to add a function and add an extra if else loop to the changeBG function. It would be more elegant if this could be done with a list variable but I've not found a way to make this work with the :class method. I hope to look into this at a later time.

Diagonal images on web page with text

Here is the effect i have tried to achieve:
When the user moves their mouse over the image, a line of text should overlay the image in a diagonal fashion.
The images could be the background to the <p>. Really just need help first with making the full thing diagonal. Do not want to use hard coded dimensions/positions that would not work on screens of different width/height.
<div class="testrows">
<div class="drow"><p>Hello World</p></div>
<div class="drow"><p>Hello World</p></div>
<div class="drowhalf">
<p>Hello World</p><p>Hello World</p>
</div>
<div class="drowhalf">
<p>Hello World</p><p>Hello World</p>
</div>
<div class="drow"><p>Hello World</p></div>
<div class="drow"><p>Hello World</p></div>
</div>
CSS
body {
background: #e5e5e5;
height:100%;
}
.testrows{
display:block;
height:100%;
}
.drow {
width: 100%;
height: 10%;
background: black;
position: absolute;
top: -50px;
left: 0;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
text-align: center;
color: #fff;
vertical-align: middle;
}
.drow p {
ms-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
padding-right: 60px;
width: 100%;
padding-bottom: 55px;
}
.drowhalf {
width: 100%;
height: 10%;
background: black;
position: absolute;
top: -50px;
left: 0;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
text-align: center;
color: #fff;
vertical-align: middle;
}
.drowhalf p {
ms-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
padding-right: 60px;
width: 50%;
padding-bottom: 55px;
}
https://jsfiddle.net/ufwmuuv4/
You can wrap all .drow elements by a wrapper (.inner-wrapper) and then rotate it (DRY), set transform-origin to top left to rotate from top left of element and finally give translateX(-50%) to .inner-wrapper to center it in its parent.
For stretching .drow, you can give width:200% to .inner-wrapper.
To calculate .drow's height, you have to use js.
Jsfiddle
function stretch(){
var $wrapper = $('.wrapper'),
diagonal = Math.ceil(Math.sqrt(Math.pow($wrapper.width(),2) + Math.pow($wrapper.height(),2))),
height = diagonal / $wrapper.find('.inner-wrapper .drow').length;
$wrapper.find('.inner-wrapper .drow').height(height).css('line-height', height + 'px');
}
$(document).ready(function(){
stretch();
});
$( window ).resize(function(){
stretch();
});
html,
body {
margin: 0;
padding: 0;
}
html,
body,
.wrapper,
.inner-wrapper {
height: 100%;
}
body {
background: #e5e5e5;
}
p {
margin: 0;
}
.wrapper {
overflow: hidden;
}
.inner-wrapper {
transform: rotate(-45deg) translateX(-50%);
transform-origin: top left;
text-align: center;
width: 200%;
}
.drow {
height: 100px;
line-height: 100px;
color: #fff;
background: rgba(0, 0, 0, 1);
}
.drowhalf p {
display: inline-block;
width: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="inner-wrapper">
<div class="drow">
<p>Hello World</p>
</div>
<div class="drow">
<p>Hello World</p>
</div>
<div class="drow drowhalf">
<p>Hello World</p><p>Hello World</p>
</div>
<div class="drow drowhalf">
<p>Hello World</p><p>Hello World</p>
</div>
<div class="drow">
<p>Hello World</p>
</div>
<div class="drow">
<p>Hello World</p>
</div>
</div>
</div>
$("div").hover(function () {
$('p').css('display', 'block');
}, function () {
$('p').css('display', 'none');
});
div {
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
margin: 100px;
height: 150px;
width: 350px;
background-image: url('http://placehold.it/350x150');
}
p {display:none}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div>
<p>Hello World</p>
</div>
You can do a rotation with transform:rotate
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
W3C as reference https://www.w3schools.com/cssref/playit.asp?filename=playcss_transform_rotate
Try to create a div and set your image as a background-img, then rotate this div.
Inside this div, put your text in a p and use jQuery to displayed it on hover.
See this on Codepen http://codepen.io/Qasph/pen/PmoNVz
Wouldn't it be better to use rotate?
I think this may be your answer:
CSS:
body {
background: #e5e5e5;
}
.aviso {
width: 50px;
height: 200px;
background: black;
position: absolute;
top: -50px;
left: 0;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
text-align: center;
color: #fff;
vertical-align: middle;
}
.aviso p {
ms-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
padding-right: 60px;
width: 100%;
padding-bottom: 55px;
}
HTML:
<div class="aviso">
<p>WIP</p>
</div>
http://codepen.io/AyrtonAlves/pen/NxMBxO
Use rotate instead of skew.
.div {
width: 200px;
height: 200px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
You can achieve this effect with pure css..
div {
margin: 100px;
height: 150px;
width: 350px;
background-image: url('http://placehold.it/350x150');
}
div:hover p{
display:block;
}
p {
display:none;
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div>
<p>Hello World</p>
</div>
Ok so it was only possible to do with Javascript and jquery. There was no CSS way to do it.
js
<script type="text/javascript">
$(window).on('resize', function (){
updateWidth();
});
function toRadians (angle) {
return angle * (Math.PI / 180);
}
function updateWidth(){
//add this to the width to make sure it fits
var idealRatio = 45.0/114;
idealHeight = 134.0;
var safetyAdd = 10;
//var topMargin = .;
var divHeightPercent = 1/6.4;
//first get the new content container height and width
var contentHeight = $('#content').height();
console.log('height:' + contentHeight);
var contentWidth = $('#content').width();
console.log('width:' + contentWidth);
//scale the hieght in proportion to the diagonal
/*
var proportion = Math.sqrt(contentHeight*contentHeight+ contentWidth*contentWidth)/(contentHeight/Math.cos(toRadians(20)));
console.log('proportion:' + proportion);
var theta = Math.atan(contentWidth/contentHeight);
var degree = 180*theta/Math.PI;
console.log('degree:' + degree);*/
//calculate the correction factor for height
var correctionFactor= (contentHeight*1.0/Math.cos(toRadians(20)))/contentHeight;
correctionFactor= (idealRatio/(contentHeight/contentWidth));
correctionFactor= 1+correctionFactor;
console.log('correctionFactor:' + correctionFactor);
divHeightPercent = divHeightPercent*correctionFactor;
console.log('divHeightPercent:' + divHeightPercent);
//topMargin=topMargin*correctionFactor;
//console.log('topMargin:' + topMargin);
//calculate the height of each section
var commonDivHeight = contentHeight*divHeightPercent;
console.log('divHeight:' + commonDivHeight);
$("#drow0").height(commonDivHeight);
$("#drow1").height(commonDivHeight);
$("#drow2").height(commonDivHeight);
$("#drow3").height(commonDivHeight);
$("#drow4").height(commonDivHeight);
$("#drow5").height(commonDivHeight);
//correctio for common div height
var cdhCorr = Math.tan(toRadians(20))*commonDivHeight;
cdhCorr = Math.sin(toRadians(20))*cdhCorr;
console.log('cdhCorr:' + cdhCorr);
var diagonalHeight = commonDivHeight/Math.cos(toRadians(20));
console.log('diagonalHeight:' + diagonalHeight);
//calculate the bottom for the first div and proper width
var zeroRowBotPoint = diagonalHeight;
console.log('zeroRowBotPoint:' + zeroRowBotPoint);
//var zeroRowWidth = zeroRowBotPoint/Math.sin(toRadians(20));//apply some correction faction here
//console.log('zeroRowWidth:' + firstRowWidth);
var zeroRowWidth = calcMaxWidthNeeded(zeroRowBotPoint, contentWidth, commonDivHeight);
$("#drow0").width(zeroRowWidth);
$("#drow0").css({top: 0});
//calculate the bottom for the first div and proper width
var firstRowBotPoint = diagonalHeight+zeroRowBotPoint;
console.log('firstRowBotPoint:' + firstRowBotPoint);
//var firstRowWidth = firstRowBotPoint/Math.sin(toRadians(20));//apply some correction faction here
//console.log('firstRowWidth:' + firstRowWidth);
var firstRowWidth = calcMaxWidthNeeded(firstRowBotPoint, contentWidth, commonDivHeight);
$("#drow1").width(firstRowWidth);
var row1padding = getLeftPadding(contentHeight, firstRowBotPoint, diagonalHeight, commonDivHeight);
$("#drow1").css({top: zeroRowBotPoint, paddingLeft: row1padding, marginRight:700});
//calculate the bottom for the second div and proper width
var secondRowBotPoint = diagonalHeight+firstRowBotPoint;
console.log('secondRowBotPoint:' + secondRowBotPoint);
//var secondRowWidth = secondRowBotPoint/Math.sin(toRadians(20));//apply some correction faction here
//console.log('secondRowWidth:' + secondRowWidth);
var secondRowWidth = calcMaxWidthNeeded(secondRowBotPoint, contentWidth, commonDivHeight);
$("#drow2").width(secondRowWidth);
var row2padding = getLeftPadding(contentHeight, secondRowBotPoint, diagonalHeight, commonDivHeight);
$("#drow2").css({top: firstRowBotPoint, paddingLeft: row2padding});
//calculate the bottom for the third div and proper width
var thirdRowBotPoint = diagonalHeight+secondRowBotPoint;
console.log('thirdRowBotPoint:' + thirdRowBotPoint);
//var thirdRowWidth = thirdRowBotPoint/Math.sin(toRadians(20));//apply some correction faction here
//console.log('thirdRowWidth:' + thirdRowWidth);
var thirdRowWidth = calcMaxWidthNeeded(thirdRowBotPoint, contentWidth, commonDivHeight);
$("#drow3").width(thirdRowWidth);
var row3padding = getLeftPadding(contentHeight, thirdRowBotPoint, diagonalHeight, commonDivHeight);
$("#drow3").css({top: secondRowBotPoint, paddingLeft: row3padding});
//calculate the bottom for the forth div and proper width
var forthRowBotPoint = diagonalHeight+thirdRowBotPoint;
console.log('forthRowBotPoint:' + forthRowBotPoint);
//var forthRowWidth = forthRowBotPoint/Math.sin(toRadians(20));//apply some correction faction here
//console.log('forthRowWidth:' + forthRowWidth);
var row4padding = getLeftPadding(contentHeight, forthRowBotPoint, diagonalHeight, commonDivHeight);
var forthRowWidth = calcMaxWidthNeeded(forthRowBotPoint, contentWidth, commonDivHeight)- row4padding;
$("#drow4").width(forthRowWidth);
var topCorrection4 = row4padding*Math.tan(toRadians(20));
console.log('topCorrection4:' + topCorrection4);
$("#drow4").css({top: thirdRowBotPoint-topCorrection4, left: row4padding});
//calculate the bottom for the fith div and proper width
var fifthRowBotPoint = diagonalHeight+forthRowBotPoint;
console.log('fifthRowBotPoint:' + fifthRowBotPoint);
//var fifthRowWidth = fifthRowBotPoint/Math.sin(toRadians(20)) - row5padding;//apply some correction faction here
//console.log('fifthRowWidth:' + fifthRowWidth);
var row5padding = getLeftPadding(contentHeight, fifthRowBotPoint, diagonalHeight, commonDivHeight);
var fifthRowWidth = calcMaxWidthNeeded(fifthRowBotPoint, contentWidth, commonDivHeight)- row5padding;
var topCorrection5 = row5padding*Math.tan(toRadians(20));
$("#drow5").width(fifthRowWidth);
$("#drow5").css({top: forthRowBotPoint-topCorrection5, left: row5padding});
/*correct the padding
//var y = contentHeight;
var row0padding = 0; //its not possible
var row1padding = getLeftPadding(contentHeight, firstRowBotPoint, diagonalHeight, commonDivHeight);
var row2padding = getLeftPadding(contentHeight, secondRowBotPoint, diagonalHeight, commonDivHeight);
var row3padding = getLeftPadding(contentHeight, thirdRowBotPoint, diagonalHeight, commonDivHeight);
var row4padding = getLeftPadding(contentHeight, forthRowBotPoint, diagonalHeight, commonDivHeight);
var row5padding = getLeftPadding(contentHeight, fifthRowBotPoint, diagonalHeight, commonDivHeight);
//*/
//get font height
var topPadding = (commonDivHeight-32)/2;
$("#rowp1").css({marginTop: topPadding, marginLeft:-250});
$("#rowp2").css({marginTop: topPadding});
$("#rowp3").css({marginTop: topPadding});
$("#rowp4").css({marginTop: topPadding});
$("#rowp5").css({marginTop: topPadding});
$("#rowp6").css({marginTop: topPadding, marginLeft:250});
//finall unhide the contents
$("#content").css({opacity:1});
}
function calcMaxWidthNeeded (bottomLoc, contentWidth, height){
//first find the width of the triangle formed by the section
var xDistance = bottomLoc/Math.tan(toRadians(20));
if(xDistance <= contentWidth){
//the width calculated by the simple function will be most efficient
console.log('Using simple Width Calculation');
return bottomLoc/Math.sin(toRadians(20));
}
var x = xDistance - contentWidth;
var bigHyp = xDistance/Math.cos(toRadians(20));
var ratio = x/xDistance;
var smallHyp = bigHyp*ratio;
//get the extra width due to the 20 degree rotaion
var extraWidth = height*Math.tan(toRadians(20));
var efficientWidth = bigHyp-smallHyp+extraWidth;
console.log('efficientWidth:' + efficientWidth);
return efficientWidth;
}
function getLeftPadding(contentHeight, bottomLoc, diagonalHeight, height){
var y = bottomLoc - contentHeight;
var x = y-diagonalHeight;
//return if there is no need to change the padding
if(x<=0){
console.log('Left padding change not required');
return 0;
}
var bottHyp = y/Math.sin(toRadians(20));
var xtoyRatio = x/y;
var topHyp = bottHyp*xtoyRatio;
//get the extra width due to the 20 degree rotaion
var extraWidth = height*Math.tan(toRadians(20));
console.log('extraWidth:' + extraWidth);
//finally calculate the padding
var paddingVal = topHyp ;
console.log('paddingVal:' + paddingVal);
return paddingVal;
}
function myFunction() {
document.querySelector('#selected').style.color='#008ed2';
updateWidth();
}
</script>
HTML
<div class="content" id="content">
<!--div class="inner-wrapper"-->
<div class="drow0" id="drow0"></div>
<div class="drow1" id="drow1"><p id="rowp1">DEVICES, IN A REALLY HUMAN WAY.</p></div>
<div class="drow2" id="drow2">
<div class="drow2-1" id="drow2-1"><p id="rowp2">EAT, DRINK AND BE MARY.</p></div>
<div class="drow2-2"><p id="rowp3">BE CAUSE.</p></div>
</div>
<div class="drow3" id="drow3">
<div class="drow3-1"><p id="rowp4">HEY, NICE PACKAGE.</p></div>
<div class="drow3-2"><p id="rowp5">WAIT FOR APPLAUSE.</p></div>
</div>
<div class="drow4" id="drow4"><p id="rowp6">WE FEEL BETTER ALREADY.</p></div>
<div class="drow5" id="drow5"></div>
<!--/div-->
</div>
CSS
.p, .drow1, .drow2, .drow3,.drow4{
margin: 0;
}
.content {
overflow: show;
position:relative;
text-align: center;
background-color: black;
color: white;
font-family: 'futura-pt-bold', sans-serif;
font-style: normal;
font-weight: 700;
font-size: 2em;
text-shadow:0px 0px 16px black;
opacity: 0;
}
.drow0, .drow1, .drow2, .drow3, .drow4, .drow5{
position:absolute;
transform: rotate(-20deg);
transform-origin: bottom left;
height:16.66%;
left:0%;
width: 100%;
background-repeat:no-repeat;
background-size:cover;
}
.drow0{
top:0%;
background-image: url("../desktop_images/1.jpg");
}
.drow1{
top:16.66%;
background-image: url("../desktop_images/2.jpg");
}
.drow2{
display: inline-flex;
top:33.33%;
}
.drow2-1{
width: 60%;
background-image: url("../desktop_images/3.jpg");
background-repeat:no-repeat;
background-size:cover;
}
.drow2-2{
width: 40%;
background-image: url("../desktop_images/4.jpg");
background-repeat:no-repeat;
background-size:cover;
}
.drow3{
display: inline-flex;
top:50%;
}
.drow3-1{
width: 45%;
background-image: url("../desktop_images/5.jpg");
background-repeat:no-repeat;
background-size:cover;
}
.drow3-2{
width: 55%;
background-image: url("../desktop_images/6.jpg");
background-repeat:no-repeat;
background-size:cover;
}
.drow4{
background-image: url("../desktop_images/7.jpg");
top:66.66%;
}
.drow5{
background-image: url("../desktop_images/8.jpg");
top:83.33%;
}
.drow1:hover {
background-repeat: no-repeat;
background-position: center;
color: transparent;
text-shadow:0px 0px 0px transparent;
background-image: url("../desktop_images/bg-2.png");
background-size: auto 65%;
}
.drow2-1:hover {
background-repeat: no-repeat;
background-position: center;
color: transparent;
text-shadow:0px 0px 0px transparent;
background-image: url("../desktop_images/bg-3.png");
background-size: 52% auto;
}
.drow2-2:hover {
background-repeat: no-repeat;
background-position: center;
color: transparent;
text-shadow:0px 0px 0px transparent;
background-image: url("../desktop_images/bg-4.png");
background-size: 75% auto;
}
.drow3-1:hover {
background-repeat: no-repeat;
background-position: center;
color: transparent;
text-shadow:0px 0px 0px transparent;
background-image: url("../desktop_images/bg-5.png");
background-size: auto 65%;
}
.drow3-2:hover {
background-repeat: no-repeat;
background-position: center;
color: transparent;
text-shadow:0px 0px 0px transparent;
background-image: url("../desktop_images/bg-6.png");
background-size: auto 65%;
}
.drow4:hover {
background-repeat: no-repeat;
background-position: center;
color: transparent;
text-shadow:0px 0px 0px transparent;
background-image: url("../desktop_images/bg-7.png");
background-size: auto 65%;
}

CSS Popup overriding browser back button

When I click the back button on the browser (the latest Firefox) after closing a popup on my dev site, the back button doesn't work, and the popup reopens, which causes a loop where the user can't use their back button.
I think it's either redirect (the # in the URL) or session related. But none of the cookie scripts seem to work. I'd like the popup to only open if the user clicks the button to open it.
Th site is currently offline. I'm just hard-coding it with a browser and a code editor at the moment.
I'm hoping someone can tell me what I'm missing. It's a pretty simple CSS popup. Here is the code for the popup:
/*Popup*/
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 50%;
position: relative;
transition: all 5s ease-in-out;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #08899e;
}
.popup .content {
max-height: 50%;
overflow: auto;
}
#media screen and (max-width: 700px){
.box{
width: 70%;
}
.popup{
width: 70%;
}
}
<a class="button" href="#popup1" data-rel="back">Let me Pop up</a>. Add more text here...
<div id="popup1" class="overlay">
<div class="popup">
<a class="close" href="#">×</a>
<h2>Title Goes Here...</h2>
<div class="content">
Text goes here....
</div>
</div>
</div>
Have you tried with this script?
if (window.location.hash) {
if (window.history && history.pushState) {
window.history.pushState("", document.title, window.location.pathname);
} else {
// Prevent scrolling by storing the page's current scroll offset
var scroll = {
top: document.body.scrollTop,
left: document.body.scrollLeft
};
window.location.hash = '';
// Restore the scroll offset, should be flicker free
document.body.scrollTop = scroll.top;
document.body.scrollLeft = scroll.left;
}
}
I also found anther article for you : [question] Close pop up on back button

Overflow hidden with border radius not working in chrome

Not sure whether it is chrome specific bug or what, but when I am transitioning child element on a parent that has overflow hidden with border radius, the overflow is visible, while the transition is in place.
var wrapper = document.getElementsByClassName('wrapper')[0],
img = document.getElementsByTagName('img')[0];
/*
Click anywhere in the bordered area to toggle img
*/
wrapper.addEventListener('click', function() {
if (!img.className) {
img.className = 'hidden';
} else {
img.className = '';
}
}, false);
.wrapper {
overflow: hidden;
border-radius: 60px;
border: 1px solid salmon;
}
img {
width: 100%;
height: auto;
opacity: 1;
transition: opacity 1s ease;
}
.hidden {
opacity: 0;
}
<div class="wrapper">
<img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>
Here's a fiddle demonstrating the issue https://jsfiddle.net/827vuyqb/2/
Any solutions, workarounds for this?
Just position the wrapper element, and give it a z-index:
var wrapper = document.getElementsByClassName('wrapper')[0],
img = document.getElementsByTagName('img')[0];
/*
Click anywhere in the bordered area to toggle img
*/
wrapper.addEventListener('click', function() {
if (!img.className) {
img.className = 'hidden';
} else {
img.className = '';
}
}, false);
.wrapper {
overflow: hidden;
border-radius: 60px;
border: 1px solid salmon;
/*Position and z-index*/
position: relative;
z-index: 1;
}
img {
width: 100%;
height: auto;
opacity: 1;
transition: opacity 1s ease;
}
.hidden {
opacity: 0;
}
<div class="wrapper">
<img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>

CSS: Position loading indicator in the center of the screen

How can I position my loading indicator in the center of the screen. Currently I'm using a little placeholder and it seems to work fine. However, when I scroll down, the loading indicator stays right in that predefined position. How can I make it follow the scrolling so that it always sits on top??
#busy
{
position: absolute;
left: 50%;
top: 35%;
display: none;
background: transparent url("../images/loading-big.gif");
z-index: 1000;
height: 31px;
width: 31px;
}
#busy-holder
{
background: transparent;
width: 100%;
height: 100%;
}
use position:fixed instead of position:absolute
The first one is relative to your screen window. (not affected by scrolling)
The second one is relative to the page. (affected by scrolling)
Note : IE6 doesn't support position:fixed.
.loader{
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('//upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Phi_fenomeni.gif/50px-Phi_fenomeni.gif')
50% 50% no-repeat rgb(249,249,249);
}
<div class="loader"></div>
This is what I've done for Angular 4:
<style type="text/css">
.centered {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform: -webkit-translate(-50%, -50%);
transform: -moz-translate(-50%, -50%);
transform: -ms-translate(-50%, -50%);
color:darkred;
}
</style>
</head>
<body>
<app-root>
<div class="centered">
<h1>Loading...</h1>
</div>
</app-root>
</body>
Here is a solution using an overlay that inhibits along with material design spinner that you configure one time in your app and you can call it from anywhere.
app.component.html
(put this somewhere at the root level of your html)
<div class="overlay" [style.height.px]="height" [style.width.px]="width" *ngIf="message.plzWait$ | async">
<mat-spinner class="plzWait" mode="indeterminate"></mat-spinner>
</div>
app.component.css
.plzWait{
position: relative;
left: calc(50% - 50px);
top:50%;
}
.overlay{
position: absolute;
top:0px;
left:0px;
width: 100%;
height: 100%;
background: black;
opacity: .5;
z-index: 999999;
}
app.component.ts
height = 0;
width = 0;
constructor(
private message: MessagingService
}
ngOnInit() {
this.height = document.body.clientHeight;
this.width = document.body.clientWidth;
}
messaging.service.ts
import { Injectable } from '#angular/core';
import { Subject } from 'rxjs';
#Injectable({
providedIn: 'root',
})
export class MessagingService {
// Observable string sources
private plzWaitObservable = new Subject<boolean>();
// Public Observables you subscribe to
public plzWait$ = this.plzWaitObservable.asObservable();
public plzWait = (wait: boolean) => this.plzWaitObservable.next(wait);
}
Some other component
constructor(private message: MessagingService) { }
somefunction() {
this.message.plzWait(true);
setTimeout(() => {
this.message.plzWait(false);
}, 5000);
}
change the position absolute of div busy to fixed
You can use this OnLoad or during fetch infos from DB
In HTML Add following code:
<div id="divLoading">
<p id="loading">
<img src="~/images/spinner.gif">
</p>
In CSS add following Code:
#divLoading {
margin: 0px;
display: none;
padding: 0px;
position: absolute;
right: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: rgb(255, 255, 255);
z-index: 30001;
opacity: 0.8;}
#loading {
position: absolute;
color: White;
top: 50%;
left: 45%;}
if you want to show and hide from JS:
document.getElementById('divLoading').style.display = 'none'; //Not Visible
document.getElementById('divLoading').style.display = 'block';//Visible
Worked for me in angular 4
by adding style="margin:0 auto;"
<mat-progress-spinner
style="margin:0 auto;"
*ngIf="isLoading"
mode="indeterminate">
</mat-progress-spinner>
transform: translate(50%, 50%);
You may try this is in my case it will work
<div class="position-relative">
<div class="position-absolute" style="transform: translate(50%, 50%)"> loader or anything Else</div>
</div>
.loader{
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('//upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Phi_fenomeni.gif/50px-Phi_fenomeni.gif')
50% 50% no-repeat rgb(249,249,249);
}
<div class="loader"></div>

Resources