25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Finishing touches<br />

There are two more small features to add to these image sliders to give <strong>Vue</strong>bnb<br />

users the best possible experience. Firstly, let's add a CSS transition to animate<br />

the translate change over a period of half a second <strong>and</strong> give a nice sliding effect.<br />

resources/assets/components/ListingSummaryGroup.vue: .listing-summaries { display: flex;<br />

flex-direction: row; justify-content: space-between; transition: transform 0.5s; }<br />

Sadly you can't see the effects of this in a book, so you'll have to try it for<br />

yourself!<br />

Finally, unlike our image carousel, these sliders are not continuous; they have a<br />

minimum <strong>and</strong> maximum value. Let's hide the appropriate arrow if that minimum<br />

or maximum is reached. For example, when the sliders load, the left arrow<br />

should be hidden because the user cannot decrement the offset further below<br />

zero.<br />

To do this, we'll use style bindings to dynamically add a visibility: hidden CSS<br />

rule.<br />

resources/assets/components/ListingSummaryGroup.vue: <br />

<br />

And the computed properties.<br />

resources/assets/components/ListingSummaryGroup.vue: computed: { ... leftArrowStyle() {<br />

return { visibility: (this.offset > 0 ? 'visible' : 'hidden') } }, rightArrowStyle() {<br />

return { visibility: ( this.offset < (this.listings.length - rowSize) ? 'visible' :<br />

'hidden' ) } } }<br />

With that done, we can see the left arrow is hidden when the page loads, as<br />

expected:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!