I have some code like this
<div ng-click="showMore = true">show more</div>
<div class="show-more' ng-show="showMore">
<div class="cell">
//some span
</div>
<div class="cell">
//some div
</div>
<div ng-click="showMore = false">show less</div>
</div>
and when user clicks 'show more', I want to show the rest in animation
in my css
.cell {
padding-top: 20px;
padding-bottom: 15px;
height: 110px;
}
I have to get rid of ng-show or ng-hide, because display:block or display:none would not make transition: height 0.5s linear; work. So I tried to set the height of .cell to be 0 when it is collapsed, and set it as 110px when it is expanded, but cell height is not really 0 when it is collapsed, because it contains <span> or <div> which have height and padding
how to animate the expand/collapse process in my case? thanks in advance
var app = angular.module("myApp", []);
// Create a Controller named "myCtrl"
app.controller("myCtrl", function($scope) {
showMore = false;
});
.show-more {
-webkit-transition: max-height 1s;
-moz-transition: max-height 1s;
-ms-transition: max-height 1s;
-o-transition: max-height 1s;
transition: max-height 1s;
background: #e5feff;
overflow: hidden;
max-height: 0;
}
.show-more.show {
max-height: 300px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div class="show-more" ng-class="{'show': showMore}">
<div class="cell">
//some span
</div>
<div class="cell">
//some div
</div>
</div>
<button type="button" ng-click="showMore = !showMore">
Show {{ showMore ? 'Less' : 'More' }} ...
</button>
</div>
Why you trying this in scripting way? Why don't you use Bootstrap Collapse class, Its all going to come with inbuilt Animations
Related
I have a parent div and a child div. Child div is displayed via v-if. I can add a transition to the child element but once the transition is over the parent's height changes abruptly and it doesn't look nice.
I'd like something like the jQuery's slideToggle() function.
Here's my html where I'm using fade effect by transitioning the opacity:
<div class="my-div">
<p>some content</p>
<transition name="fade" mode="out-in">
<p key=1 v-if="show">hello</p>
</transition>
</div>
and here's the transition css:
.fade-enter-active,
.fade-leave-active {
transition: opacity .5s
}
.fade-enter,
.fade-leave-to {
opacity: 0
}
.my-div {
background: lightgreen;
}
Here is the fiddle with my code:
https://jsfiddle.net/x15Lw6a3/
I don't know how to make the height transition. I've tried switching from opacity to height and to max-height as per some other questions but it just snaps up and down.
Any idea or a link to tutorial is appreciated. Thanks!
Try using max-height property by adding max-height: 100px; to fade-enter-active,
.fade-leave-active rule and in .fade-enter,
.fade-leave-to rule set it 0 as follows:
Vue.config.devtools = false;
Vue.config.productionTip = false;
new Vue({
el: '#demo',
data: {
show: true
}
})
.fade-enter-active,
.fade-leave-active {
transition: all 0.5s ease;
max-height: 100px;
opacity: 1;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
max-height: 0px;
}
.my-div {
background: lightgreen;
}
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="demo">
<button v-on:click="show = !show">
Toggle
</button>
<div class="my-div">
<p>some content</p>
<transition name="fade" mode="out-in">
<p key=1 v-if="show" >hello</p>
</transition>
</div>
</div>
Note:
You could see that the animation is not perfectly smooth
Tried a number of approaches myself, ended up going for a component, and VueSlideToggle does the job perfectly for me. It makes use of CSS transition targeting the height property.
new Vue({
el: '#demo',
data() {
return {
show: true
}
}
});
.my-div {
background: lightgreen;
}
<div id="demo">
<button v-on:click="show = !show">Toggle</button>
<div class="my-div">
<p>some content</p>
<vue-slide-toggle :open="show" tag="div" :duration="500">
<p v-if="show">hello</p>
</vue-slide-toggle>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/vue-slide-toggle"></script>
for my site I have finally created a load more option, with a clickable image that when clicked loads the next posts.
However, I want to add an effect to the image so when one hovers over the "plus" spins. Since the link area is above the image the "plus" no longer spins.
Any thoughts on how to resolve this without potentially breaking the plugin, behind this load more function in wordpress ?
a.load_more { border-radius: 70%; height:26%; width:15%; position: absolute; top:3%; left:1.5%; display:block; background:rgba(0,255,0,0.5);}
img.plus{
-webkit-transition: -webkit-transform .8s ease-in-out;
-ms-transition: -ms-transform .8s ease-in-out;
transition: transform .8s ease-in-out;
z-index:999
}
img.plus:hover{
transform:rotate(360deg);
-ms-transform:rotate(360deg);
-webkit-transform:rotate(360deg);
}
<div id="content">
<div id="block">
<div>
<img class="plus" src="http://www.hellodolly.be/wp-content/uploads/2016/10/plus.png"/>
</div>
</div>
</div><!--/content-->
fiddle
you can put the link around the image so the image is the link you dont even need a class for the href then.
example:
<div id="content">
<div id="block">
<div>
<a href="#" class="load_more">
<img class="plus" src="http://www.hellodolly.be/wp-content/uploads/2016/10/plus.png"/>
</a>
</div>
</div>
</div><!--/content-->
I hope that i have understand you're question correct and that this will help you.
try to add "visibility: hidden"
.load_more {
border-radius: 70%;
height:29%;
width:11%;
position: absolute;
top:3%; left:1.2%;
display:block;
background:rgba(0,255,0,0.5);
visibility: hidden;
}
Just change your markup into like this. Wrap the image by anchor.
img.plus{
-webkit-transition: -webkit-transform .8s ease-in-out;
-ms-transition: -ms-transform .8s ease-in-out;
transition: transform .8s ease-in-out;
z-index:999
}
img.plus:hover{
transform:rotate(360deg);
-ms-transform:rotate(360deg);
-webkit-transform:rotate(360deg);
}
<div id="content">
<div id="block">
<div>
<img class="plus" src="http://www.hellodolly.be/wp-content/uploads/2016/10/plus.png"/>
</div>
</div>
</div><!--/content-->
Hope it helps. Cheers
Im working with angular-material md-sidenav element, it's on the left side and when i click on it it fold left. this closing/folding action is done with css transform: translate3d(-100%,0,0), but after reading about it i understand that in order to save resources it 'freeze' the element as an image during the transform, this cause a delay for about a second(i think), visible to the user. i am looking for a replacement with the same folding animation.
i added position:relative style to the md-sidenav,it gave the element the behavior i needed but it's in the core if this issue.
html:
<div ng-app="myModule">
<div ng-controller="myCtrl" layout="column" style="height: 100%;" ng-cloak>
<section layout="row" flex>
<md-sidenav class="md-sidenav-left" md-component-id="left"
md-disable-backdrop md-whiteframe="4" style="position: relative;">
<md-toolbar class="md-theme-indigo">
<h1 class="md-toolbar-tools">Disabled Backdrop</h1>
</md-toolbar>
<md-content layout-margin>
</md-content>
</md-sidenav>
<md-content flex >
<md-toolbar layout="row">
testing123
</md-toolbar>
<div layout="column" layout-align="top center" style="background-color:#ff5252;">
<div>
<md-button ng-click="toggleLeft()" class="md-raised">
Toggle Sidenav
</md-button>
</div>
</div>
</md-content>
</section>
</div>
</div>
js:
angular.module('myModule', ['ngMaterial'])
.controller('myCtrl', function ($scope, $timeout, $mdSidenav) {
$scope.toggleLeft = buildToggler('left');
$scope.toggleRight = buildToggler('right');
function buildToggler(componentId) {
return function() {
$mdSidenav(componentId).toggle();
}
}
});
css:
.md-sidenav-left.md-closed, md-sidenav.md-closed {
//original angular-matireal code
-webkit-transform: translate3d(-100%,0,0) !important;
transform: translate3d(-100%,0,0) !important;
/* my tempoory solution */
/* -webkit-transform: translate3d(0,0,0) !important;
transform: translate3d(0,0,0) !important; */
}
https://jsfiddle.net/suunyz3e/340/
i found a solution/walk around for now using margin-left, position:absolute and transition: all 0.25s ease-in-out/ease-out.
html:
<div ng-app="myModule">
<div ng-controller="myCtrl" layout="column" style="height: 100%;" ng-cloak>
<section layout="row" flex>
<md-sidenav class="md-sidenav-left sidenav-container" md-component-id="left"
md-disable-backdrop md-whiteframe="4" >
<md-toolbar class="md-theme-indigo">
<h1 class="md-toolbar-tools">Disabled Backdrop</h1>
</md-toolbar>
<md-content layout-margin>
</md-content>
</md-sidenav>
<md-content flex class="delay-fix-md-content" ng-class="{'walk-around-sidenav-collapse':(isToggleSidenav === true)}">
<md-toolbar layout="row">
testing123
</md-toolbar>
<div layout="column" layout-align="top center" style="background-color:#ff5252;">
<div>
<md-button ng-click="toggleSidenav('left')" class="md-raised">
Toggle Sidenav
</md-button>
</div>
</div>
</md-content>
</section>
</div>
</div>
css:
.delay-fix-md-content{
margin-left:320px !important;
-webkit-transition: all 0.25s ease-in-out !important;
-moz-transition: all 0.25s ease-in-out !important;
transition: all 0.25s ease-in-out !important;
}
.walk-around-sidenav-collapse{
margin-left:0px !important;
-webkit-transition: all 0.25s ease-out !important;
-moz-transition: all 0.25s ease-out !important;
transition: all 0.25s ease-out !important;
}
.sidenav-container{
position: absolute;
-webkit-transition: all 0.25s ease-in-out !important;
-moz-transition: all 0.25s ease-in-out !important;
transition: all 0.25s ease-in-out !important;
}
js:
angular.module('myModule', ['ngMaterial'])
.controller('myCtrl', function ($scope, $timeout, $mdSidenav) {
$scope.isToggleSidenav = true;
$scope.toggleSidenav = function (menuId) {
$mdSidenav(menuId).toggle();
$scope.isToggleSidenav = !$scope.isToggleSidenav;
};
});
https://jsfiddle.net/suunyz3e/342/
I am using wordpress with woocommerce to create eshop. Woocommerce has part called mini-cart.php it is actual cart of customer. However I need this cart to be max 60% of height of whole site and I need content of cart to be scrollable. This would be easy but the second thing I need is to exclude buttons and total from scrolling. I have tried many ways but it never works. Here is code I use:
<div class="cart active">
<div class="cart-wrapper">
<h1 class="widget-title"> </h1><div class="widget_shopping_cart_content"><div class="cart-product-list">
<ul class="cart_list product_list_widget ">
<li><a href="http://autoflex.zone42.sk/obchod/2x-stabilizator-predna-naprava-porsche-911-od-09-1997/">
<img src="http://autoflex.zone42.sk/wp-content/uploads/2013/10/2x-stabilizátor-predná-náprava-Porsche-Boxster-od-09.1996-90x90.jpg" class="attachment-shop_thumbnail wp-post-image" alt="2x stabilizátor predná náprava Porsche 911 od: 09.1997" height="90" width="90">
2x stabilizátor predná náprava Porsche 911 od: 09.1997
</a>
<p class="quantity">1 × <span class="amount">50,90€</span></p>
</li>
</ul>
</div><!-- end product list -->
<p class="total"><strong>Medzisúčet:</strong> <span class="amount">50,90€</span></p>
<div class="buttons">
<a href="http://autoflex.zone42.sk/kosik/" class="button">
<div class="cart-buttons">
<div class="cart-buttons-padding">
Zobraziť košík → </div>
</div>
</a>
<a href="http://autoflex.zone42.sk/pokladna/" class="button checkout">
<div class="cart-buttons">
<div class="cart-buttons-padding">
pokladňa → </div>
</div>
</a>
</div>
</div>
and here is CSS:
.cart.active{
max-height: 60%;
margin-bottom: -25px;
transition: max-height .5s .2s;
-ms-transition: max-height .5s .2s;
-moz-transition: max-height .5s .2s;
-webkit-transition: max-height .5s .2s;
}
div.facebook:hover, div.mail-us:hover, div.move-up:hover, div.cart-total.hoverOn:hover{
right: 150px;
}
div.cart-total.hoverOn{
transition: all .5s, width .5s .5s;
}
div.cart-total.hoverOff{
transition: all .5s, width .2s;
right: 150px;
width: 279px;
}
.cart-product-list{
overflow-y: auto;
}
so what should I do if I want only ul (cart_list) scrollable? and I also want the whole div name cart active to be max 60% height of whole site? Thanks in forward
ul.cart_list {
overflow: scroll;
}
I have such dom structure:
<div class="wrapper">
<div class="style1"> ... another divs ... </div>
</div>
<div class="wrapper">
<div class="style2"> ... another divs ... </div>
</div>
<div class="wrapper">
<div class="style1"> ... another divs ... </div>
</div>
<div class="wrapper">
<div class="style2"> ... another divs ... </div>
</div>
<div class="wrapper">
<div class="style1"> ... another divs ... </div>
</div>
In style1 and style2 there is background-color settings for all inner divs (marked as 'another divs').
Now I want to make background transation for all divs inside style1 and style2:
.wrapper :hover
{
background-color: #ccc;
}
.wrapper
{
-moz-transition: background .2s linear;
-webkit-transition: background .2s linear;
-o-transition: background .2s linear;
transition: background .2s linear;
}
It doesn't work (nothing changes). When I set hover propery for style1 and style2 it changes background, but only active dive the mouse is over.
Remove the space between .wrapper and :hover. But I may have mis-read this. You might want to do .wrapper:hover .style1 div{}
If I understand you right you want to show/mark every div that has certain style. So upon hovering single div.style1 you want to mark all style1 divs. I don't know how to achieve this only with css buth with a little jquery/javascript help I got something like this:
CHANGED CSS
.wrapper_hover
{
background-color: #ccc;
}
.wrapper
{
-moz-transition: background .2s linear;
-webkit-transition: background .2s linear;
-o-transition: background .2s linear;
transition: background .2s linear;
}
JQUERY CODE
$("div").hover(
function () {
$(".style1").addClass("wrapper_hover");
},
function () {
$(".style1").removeClass("wrapper_hover");
}
);