25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Opening<br />

First, let's add a Boolean data property that will represent the opened or closed<br />

state of our modal. We'll initialize it to false.<br />

app.<strong>js</strong>: data: { ... modalOpen: false }<br />

We'll make it so that clicking our header image will set the modal to open. We'll<br />

also overlay a button labelled View Photos in the bottom-left corner of the<br />

header image to give a stronger signal to the user that they should click to show<br />

the image.<br />

index.html: View Photos <br />

Note that, by putting the click listener on the wrapping div, the click event will<br />

be captured regardless of whether the user clicks the button or the div due to<br />

DOM event propagation.<br />

We'll add some more CSS to our header image to make the cursor a pointer,<br />

letting the user know the header can be clicked, <strong>and</strong> giving the header a relative<br />

position so the button can be positioned within it. We'll also add rules to style the<br />

button.<br />

style.css: .header .header-img { ... cursor: pointer; position: relative; } button {<br />

border-radius: 4px; border: 1px solid #c4c4c4; text-align: center; vertical-align:<br />

middle; font-weight: bold; line-height: 1.43; user-select: none; white-space:<br />

nowrap; cursor: pointer; background: white; color: #484848; padding: 7px 18px;<br />

font-size: 14px; display: inline-block; margin-bottom: 0; } .header .header-img<br />

.view-photos { position: absolute; bottom: 20px; left: 20px; }<br />

Let's now add the markup for our modal. I've put it after the other elements in<br />

the page, though it doesn't really matter as the modal will be out of the regular

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

Saved successfully!

Ooh no, something went wrong!