<template>
<section class="v-portfolio portfolio">
<div class="container">
<h2 class="title--section">Портфолио</h2>
<div class="portfolio__wrap">
<v-portfolio-item
v-for="work in portfolio"
:key="work.id"
:portfolio_data="work"
/>
</div>
<div class="portfolio__hidden">
<div class="portfolio__wrap-hidden">
<!-- <v-portfolio-item
v-for="work in portfolio"
:key="work.id"
:portfolio_data="work"
/> -->
<v-portfolio-item-hidden
v-for="workHidden in portfolioHidden"
:key="workHidden.id"
:portfolio_data_hidden="workHidden"
/>
</div>
</div>
</div>
<button class="portfolio__dropdown-btn learn-more" @click="toggle">
<span class="circle" aria-hidden="true">
<span class="icon arrow"></span>
</span>
<!-- <span class="button-text">{{btn}}</span> -->
<!-- <span class="button-text">Смотреть больше</span> -->
<span class="button-text">{{btnText}}</span>
</button>
</section>
</template>
<script>
import vPortfolioItem from './v-portfolio-item'
import vPortfolioItemHidden from './v-portfolio-item-hidden'
export default {
name: 'v-portfolio',
components: {
vPortfolioItem,
vPortfolioItemHidden
},
data() {
return {
portfolio: [
{
image: 'med-clinic.jpg',
id: '1'
},
{
image: 'savanna.jpg',
id: '2'
},
{
image: 'bedroom-market.jpg',
link: 'https://bedroom-market.000webhostapp.com/',
id: '3'
},
{
image: 'fish-market.jpg',
id: '4'
},
{
image: 'music-arsenal.jpg',
id: '5'
},
{
image: 'build-home.jpg',
id: '6'
},
],
portfolioHidden: [
{
image: 'mosteo.jpg',
link: '',
id: '1'
},
{
image: 'medical-expres.jpg',
link: '',
id: '2'
},
{
image: 'kamen.jpg',
link: '',
id: '3'
},
{
image: 'market-sale.jpg',
link: '',
id: '4'
},
],
// btn: 'Показать',
// toggle1: false
}
},
methods: {
toggle(){
let container = document.querySelector('.portfolio__hidden')
if (!container.classList.contains('active')) {
container.classList.add('active');
container.style.height = 'auto';
let height = container.clientHeight + 'px';
container.style.height = '0px';
setTimeout(function () {
container.style.height = height;
}, 0);
} else {
container.style.height = '0px';
container.addEventListener('transitionend', function () {
container.classList.remove('active');
}, {once: true});
}
}
},
computed: {
btnText: function() {
if(this.toggle1) {
return 'Скрыть'
}
return 'Показать'
}
}
}
</script>
<style>
.portfolio__hidden {
-webkit-transition: height 0.5s ease;
-o-transition: height 0.5s ease;
transition: height 0.5s ease;
overflow: hidden;
}
.portfolio__hidden:not(.active) {
display: none;
}
</style>
<button class="portfolio__dropdown-btn learn-more" @click="toggle = !toggle">
<span class="circle" aria-hidden="true">
<span class="icon arrow"></span>
</span>
<!-- <span class="button-text">{{btn}}</span> -->
<!-- <span class="button-text">Смотреть больше</span> -->
<span class="button-text">{{btnText}}</span>
</button>
поменял , не работает <template>
<section class="v-portfolio portfolio">
<div class="container">
<h2 class="title--section">Портфолио</h2>
<div class="portfolio__wrap">
<v-portfolio-item
v-for="work in portfolio"
:key="work.id"
:portfolio_data="work"
/>
</div>
<div class="portfolio__hidden" v-if="toggle1">
<div class="portfolio__wrap-hidden">
<v-portfolio-item
v-for="work in portfolio"
:key="work.id"
:portfolio_data="work"
/>
</div>
</div>
</div>
<button class="portfolio__dropdown-btn learn-more" @click="toggle1 = !toggle1">
<span class="circle" aria-hidden="true">
<span class="icon arrow"></span>
</span>
<!-- <span class="button-text">{{btn}}</span> -->
<!-- <span class="button-text">Смотреть больше</span> -->
<span class="button-text">{{btnText}}</span>
</button>
</section>
</template>
<script>
import vPortfolioItem from './v-portfolio-item'
export default {
name: 'v-portfolio',
components: {
vPortfolioItem
},
data() {
return {
portfolio: [
{
image: 'med-clinic.jpg',
id: '1'
},
{
image: 'savanna.jpg',
id: '2'
},
{
image: 'bedroom-market.jpg',
id: '3'
},
{
image: 'fish-market.jpg',
id: '4'
},
{
image: 'music-arsenal.jpg',
id: '5'
},
{
image: 'build-home.jpg',
id: '6'
},
],
// btn: 'Показать',
toggle1: false
}
},
methods: {
toggle(){
let container = document.querySelector('.portfolio__hidden')
if (!container.classList.contains('active')) {
container.classList.add('active');
container.style.height = 'auto';
let height = container.clientHeight + 'px';
container.style.height = '0px';
setTimeout(function () {
container.style.height = height;
}, 0);
} else {
container.style.height = '0px';
container.addEventListener('transitionend', function () {
container.classList.remove('active');
}, {once: true});
}
}
},
computed: {
btnText: function() {
if(this.toggle1) {
return 'Скрыть'
}
return 'Показать'
}
}
}
</script>
<style>
.portfolio__hidden {
-webkit-transition: height 0.5s ease;
-o-transition: height 0.5s ease;
transition: height 0.5s ease;
overflow: hidden;
}
.portfolio__hidden:not(.active) {
display: none;
}
</style>
НО не работает анимация в методе toggle при клике, поскольку она привязана была к кнопке