I use AngularJS.
I need to make next things:
When I click 'Fade in' - the hidden element should appear (slide out) from left side. But it should slide behind 'MAIN BASE' element and it should look like DRAGGER drags it out from left to right. How to implement it? any ideas?
.base {
height: 50px;
width: 300px;
border: 1px solid blue;
}
.faded {
border: 1px solid greenyellow;
width: 200px;
}
.dragger {
height: 50px;
width: 100%;
border: 1px solid green;
}
.fade.ng-enter {
transition: 0.9s linear all;
width: 0;
}
.fade.ng-enter.ng-enter-active {
width: 100%;
}
<div layout="row">
<div class="base">MAIN BASE</div>
<div ng-if="bool" class=" faded fade"> Hidden element </div>
<div class="dragger">DRAGGER</div>
</div>
<button ng-click="bool=true">Fade In!</button>
<button ng-click="bool=false">Fade Out!</button>
Solved. used:
.animation('.slide', ['$animateCss', function($animateCss) {
return {
enter: function(element) {
return $animateCss(element, {
event: 'enter',
structural: true,
from: { 'margin-left': -300},
to: { 'margin-left': 0},
duration: 0.3
});
}
}
}])
<div layout="row">
<div class="base">MAIN BASE</div>
<div ng-if="bool" class=" faded slide"> Hidden element </div>
<div class="dragger">DRAGGER</div>
</div>
<button ng-click="bool=true">Fade In!</button>
<button ng-click="bool=false">Fade Out!</button>
Related
I'm setting up some conceptual functions (hence the probably botched way this is put together), but I'm running into an unforeseen issue with using position : absolute on the toast elements. On the right-hand products there's no issue besides the toast overlapping the products to its left (which is fine in this case), but when it triggers on the left column it extends outside the viewport.
That's why the class="diamond" is outside the toast itself, so that it can remain static regardless of the toast's position, since I assume position : absolute is not the ideal positioning for the toast.
So my question is, how can I achieve the intended effect of the toast triggering but remaining inside the viewport? My intention is for the diamond to be "anchored" to the button, with the toast itself dynamic on the horizontal axis.
Click the red square to open the toast, and the green one inside to close it.
function open(event) {
if (!event.target.closest(".product button")){
return false;
}
const parent = event.target.closest(".product");
const toast = parent.querySelector('.toast');
const diamond = parent.querySelector('.diamond');
toast.style.display = 'block';
diamond.style.display = 'block';
}
function close(event) {
if (!event.target.closest(".toast button")){
return false;
}
const product = event.target.closest(".product");
const toast = event.target.closest(".toast");
product.querySelector('.diamond').style.display = 'none';
toast.style.display = 'none';
}
addEventListener('click', open);
addEventListener('click', close);
.container {
display : flex;
flex-flow: row wrap;
justify-content : space-around;
height : 450px;
width : 300px;
background-color : grey;
}
.product {
position : relative;
height : 200px;
width : 130px;
background-color : blue;
}
.icon {
position : absolute;
top : 10px;
right : 10px;
height : 30px;
width : 30px;
background-color : red;
}
.diamond {
position : absolute;
display : none;
height : 10px;
width : 10px;
top : 50px;
right : 20px;
background-color : black;
transform : rotate(45deg);
}
.toast {
position : absolute;
display : none;
width : 160px;
height : 50px;
top : 55px;
right : 10px;
background-color : black;
border-style: solid;
border-width : thin;
border-color : red;
}
.close {
position : absolute;
display : block;
width : 20px;
height : 20px;
top : 15px;
right : 70px;
background-color : green;
}
<div class="container">
<div class="product">
<button class="icon"></button>
<div class="diamond"></div>
<div class="toast">
<button class="close"></button>
</div>
</div>
<div class="product">
<button class="icon"></button>
<div class="diamond"></div>
<div class="toast">
<button class="close"></button>
</div>
</div>
<div class="product">
<button class="icon"></button>
<div class="diamond"></div>
<div class="toast">
<button class="close"></button>
</div>
</div>
<div class="product">
<button class="icon"></button>
<div class="diamond"></div>
<div class="toast">
<button class="close"></button>
</div>
</div>
</div>
This can be the possible solution. Please replace toast css with the below css:
.toast {
position: absolute;
display: none;
width: 100%;
height: 50px;
top: 55px;
right: 0;
background-color: black;
border-style: solid;
border-width: thin;
border-color: red;
}
Hope this will help you!
When I change the style of my input, the labels and the value of the cursor disappear...
I don't know what's the matter...
Before :
Then, now that I changed the style :
The code :
#slidecontainer {
margin: 0 auto;
background-color: #afe0fc;
padding: 1.5em;
border-radius: 5px;
}
/* Styling the slider background */
#range {
-webkit-appearance: none;
background-color: grey;
outline: none;
height: 3px;
border-radius: 1px;
width:100%;
}
/* Styling the thumb */
#range::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
background: #078dd8;
border-radius: 50%;
cursor: -moz-grab;
cursor: -webkit-grab;
}
<div class="panel-body">
<div class="container-fluid" id="slidecontainer">
<input
id="range"
type="range"
data-slider-ticks="[0, 100, 200, 300, 400, 500]"
data-slider-ticks-snap-bounds="10"
data-slider-ticks-labels='["0€", "100€", "200€", "300€", "400€", "500€"]'
/>
</div>
</div>
Thanks for any explanations or help
Ensure you are including the bootstrap-slider namespace if not using jQuery.
"data-provide="slider"
<div class="panel-body">
<div class="container-fluid" id="slidecontainer">
<input
id="range"
type="range"
data-provide="slider"
data-slider-ticks="[0, 100, 200, 300, 400, 500]"
data-slider-ticks-snap-bounds="10"
data-slider-ticks-labels='["0€", "100€", "200€", "300€", "400€", "500€"]'
/>
</div>
</div>
with jQuery:
$('#slidecontainer input').slider();
without JQuery
var slider = new Slider('#slidecontainer input', {});
further examples found: https://seiyria.com/bootstrap-slider/#example-13
I am trying to achieve this layout but I'm having problems with setting a background, which should be 50% of the screen size. I thought of setting up an image as background, but there are different colors that should be different on each page.
Is it possible to achieve it using only background-color?
This is how I set the HTML, TS & CSS so far:
<div [class]="getBackground(title)">
<div class="background-header">
<img [src]="'assets/assess/Custom.png'" alt="">
{{title}}
</div>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" *ngFor="let theme of pillar.data; let i = index">
<button rh-btn-theme full-btn [ngClass]="{'ripple': true}" [issue]="theme" (click)="presentModal($event, theme);"></button>
</div>
</div>
</div>
</div>
TS
getBackground(pillar) {
switch (pillar) {
case "People":
return "background-people";
case "Land":
return "background-land";
case "Crop":
return "background-crop";
case "Business":
return "background-business";
default:
return "background-custom";
}
}
CSS
.background-header {
width: 100%;
height: 80%;
display: block;
position: relative;
img {
display: inherit;
background-color: #000;
}
}
.background-people {
background-color: #335F6E;
}
.background-land {
background-color: #006533;
}
.background-crop {
background-color: #7F4020;
}
.background-business {
background-color: #F8DC0B;
}
.background-custom {
background-color: map-get($colors, primary);
}
Yes you can do it by background gradient:
.content {
width: 100%;
height: 300px;
border: solid 2px #123;
background: linear-gradient( red, red 50%, white 50%, white);
}
<div class='content'></div>
Dont forget genarte cross-browser css. See about background gradient here
Im very new to frontend development & angular 2. I was trying to program a floating button on the right bottom of the webapp that would allow users to open the shopping cart if needed (cart-button). The problem I have is that the button appears on the screen, put it does not readjust its position once scrolled down, its position is fixed to one spot and it wont move.
HTML:
<md-sidenav-container class="example-container">
<md-sidenav #sidenav class="example-sidenav">
<div class="scroll">
<md-card *ngFor="let ticket of shoppingCart">
<md-card-title>{{ticket.product.name}}</md-card-title>
<md-card-subtitle>$ {{ticket.product.price}}</md-card-subtitle>
<md-card-subtitle>Quantity: {{ticket.quantity}}</md-card-subtitle>
<button md-icon-button (click)="removeProduct(ticket.product)">
<md-icon>delete</md-icon>
</button>
</md-card>
<button md-button class="checkout" (click)="openDialog()">CHECKOUT</button>
</div>
</md-sidenav>
<div id="cart-button">
<button md-icon-button (click)="openNav(sidenav)" id = "cart-button2">
<md-icon>shopping_cart</md-icon>
</button>
</div>
<app-banner *ngIf="!featured"></app-banner>
<form *ngIf="!featured" class="cont">
<md-input-container class="search">
<input mdInput placeholder="Search" type="text" (keyup)="onKeyUp(search.value)" #search>
</md-input-container>
<md-select placeholder="Categories" class="category">
<md-option *ngFor="let category of categories" (click)="change(category)">
{{ category }}
</md-option>
</md-select>
</form>
<md-grid-list cols="5" rowHeight="1:1.4" class="size">
<md-grid-tile *ngFor="let product of products" class="separation">
<md-card class="example-card">
<md-card-header>
<div md-card-avatar class="example-header-image"></div>
<md-card-title>${{product.price}}</md-card-title>
<md-card-subtitle>{{product.name}}</md-card-subtitle>
</md-card-header>
<div class="image-container" [ngStyle]="{'background-image': 'url(' + product.imgUrl + ')'}" [routerLink]="['/product', product.id]">
</div>
<md-card-actions>
<button md-button (click)="addToCart(product.id, 1, sidenav)">ADD TO CART</button>
</md-card-actions>
</md-card>
</md-grid-tile>
</md-grid-list>
<div id="fidget-spinner-container" *ngIf="firstLoad">
<md-spinner id="fidget-spinner" *ngIf="!featured"></md-spinner>
</div>
</md-sidenav-container>
CSS:
.size {
width: 1400px;
margin:100px auto;
}
.example-card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,.3);
transition: 0.3s;
width: 400%;
border-radius: 5px;
}
.example-card:hover {
box-shadow: 0 10px 20px 0 rgba(0,0,0,0.5);
}
.example-header-image {
background-image: url('https://img2.hkrtcdn.com/1434/prd_143361_c_l.jpg');
background-size: cover;
}
.example-container {
position: relative;
width: 100%;
height: 100%;
border: 1px solid rgba(0, 0, 0, 0.5);
}
.example-sidenav-content {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
.example-sidenav {
padding: 100px 50px 0 50px;
width: 250px;
}
.checkout {
bottom: 30px;
position: fixed;
}
.image-container {
width: 200px;
height: 200px;
background: white center no-repeat;
background-size: contain;
}
.mat-card-image:first-child {
margin-top: 0 !important;
}
.example-card {
margin:15px;
}
.scroll {
overflow-x: auto;
width:100%;
height:80%;
}
.cont {
width:70%;
padding-right:15%;
padding-left:15%;
padding-top: 330px;
display: inline-flex;
}
.search {
width:70%;
padding-left:10%;
/*margin-left: 30%;*/
/*margin-right: 30%;*/
}
#fidget-spinner {
margin:auto;
padding-bottom:50px;
}
.mat-option {
color: black;
}
#cart-button {
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color: #666666;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
}
.cart-button2 {
margin-top:22px;
}
.category {
padding-right:10%;
padding-top: 10.4px;
width:20%;
}
What I do typically is this in my main module component:
template: `
<div class="container-fluid" [ngStyle]="containerDivSize">
<router-outlet>
</router-outlet>
</div>
`,
So the template above for the container defines the div to be exactly the size of the screen, and by way of setting an Observer on window resize events below, containerDivSize adapts to changes in the window size and orientation, so if the user resizes the window we get the updates. This means we know the exact pixel dimensions of the screen, and we size our containing div to fill the window regardless of any changes.
containerDivSize: any;
constructor(){}
ngOnInit() {
Observable.fromEvent(window, 'resize')
.map(getWindowSize)
.subscribe(
windowSize$ => {
var windowHeight = windowSize$.height;
var windowWidth = windowSize$.width;
this.containerDivSize = {
'height': windowHeight + 'px'
'width': windowHeight + 'px'
}
});
}
You can use this same method to define a button position style that takes the window width and height, subtract the button size and apply it to your button, which will always stay fixed just inside the bottom right corner of the window no matter what the user does (scroll or resize the window).
Maybe something like this:
buttonPosition: any;
var buttonVerticalPosition = windowSize$.height-50;
var buttonHorizontalPosition = windowSize$.width-120;
this.buttonPosition = {
'position': 'absolute',
'top': buttonVerticalPosition + 'px',
'left': buttonHorizontalPosition + 'px'
}
Then add that class to your button.
<button class="btn btn-sm btn-default buttonPosition" >View Cart</button>
The problem is you are using Materal2 which is using transform3D in its style. Due to this relative postion is not working. You should place your button in this component. It takes whatever you put in it and places it in the body.
Other solutions are registering to a scroll event and re-setting the position everytime. This results in poor performance on mobile.
I have 3 divs. 2 of them change their color when focused. Can also an action be performed on another div when 2 of them get focused?
div {
border: 1px solid;
margin: 5px;
width: 300px;
height: 50px;
padding: 2px;
}
.myClass:focus {
background-color: yellow;
outline: none;
}
<div class="myClass" tabindex="-1">
Focus me!
</div>
<div class="myClass" tabindex="-1">
You can focus me too!
</div>
<hr />
<div class="anotherClass">
I cannot be focused, but want to change my color, when one of the other divs above me get focused.
</div>
So when 1 of the 2 upper divs get focused I want the 3rd div at the bottom to change its color.
Here you can have a look: https://jsfiddle.net/ogpvvwtg/
Sure, you can use the general sibling selector ~
.myClass:focus ~ .anotherClass {
background-color: red;
outline: none;
}
div {
border: 1px solid;
margin: 5px;
width: 300px;
height: 50px;
padding: 2px;
}
.myClass:focus {
background-color: yellow;
outline: none;
}
.myClass:focus ~ .anotherClass {
background-color: red;
outline: none;
}
<div class="myClass" tabindex="-1">
Focus me!
</div>
<div class="myClass" tabindex="-1">
You can focus me too!
</div>
<hr />
<div class="anotherClass">
I cannot be focused, but want to change my color, when one of the other divs above me get focused.
</div>
you can do this with a little bit of javascript which might give you more control of the things you want to color.
colorDiv3 = function() {
window.document.getElementById("div3").style.backgroundColor = "lightGreen";
}
div {
border: 1px solid;
margin: 5px;
width: 300px;
height: 50px;
padding: 2px;
}
.myClass:focus {
background-color: yellow;
outline: none;
}
<div class="myClass" tabindex="-1" onFocus="colorDiv3()">
Focus me!
</div>
<div class="myClass" tabindex="-1" onFocus="colorDiv3()">
You can focus me too!
</div>
<hr />
<div id="div3" class="anotherClass">
I cannot be focused, but want to change my color, when one of the other divs above me get focused.
</div>
You can also accomplish this using JavaScript:
First give the divs IDs:
<div id="topDiv" class="myClass" tabindex="-1">
etc...
Then you can find them with:
var top_div = document.getElementById('top_div');
var middle_div = document.getElementById('middle_div');
var bottom_div = document.getElementById('bottom_div');
Assign an event listener to the objects. This allows you to call a function when an element is focused:
top_div.addEventListener("focus", changeBottomDivColor);
middle_div.addEventListener("focus", changeBottomDivColor);
And finally, the function to actually change the color:
function changeBottomDivColor() {
bottom_div.style.backgroundColor = "red";
}