0

I'm new in web develop. I want to realize a function that when I click the link "click to see sample colors", it will popup a page like the picture to show all my sample colors. But I don't know what kind of technics to use to do it. I have search on w3schools. But the popup window or popup boxes using javaScript is not what I want.

Could you help me to realize the effect using a simple way?

Thank you very much!!

3 Answers 3

1

I believe I understand what you're saying. Here is a codepen example that uses a CSS modal box instead. Check it out:

http://codepen.io/ShadyAlzayat/pen/LEDJg

The modal code is as follows:

.modal {
opacity: 0;
visibility: hidden;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align: left;
background: rgba(0,0,0, .9);
transition: opacity .25s ease;
}

.modal__bg {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
cursor: pointer;
}

.modal-state {
display: none;
}

.modal-state:checked + .modal {
opacity: 1;
visibility: visible;
}

.modal-state:checked + .modal .modal__inner {
top: 0;
}

.modal__inner {
transition: top .25s ease;
position: absolute;
top: -20%;
right: 0;
bottom: 0;
left: 0;
width: 50%;
margin: auto;
overflow: auto;
background: #fff;
border-radius: 5px;
padding: 1em 2em;
height: 50%;
}

.modal__close {
position: absolute;
right: 1em;
top: 1em;
width: 1.1em;
height: 1.1em;
cursor: pointer;
}

.modal__close:after,
.modal__close:before {
content: '';
position: absolute;
width: 2px;
height: 1.5em;
background: #ccc;
display: block;
transform: rotate(45deg);
left: 50%;
margin: -3px 0 0 -1px;
top: 0;
}

.modal__close:hover:after,
.modal__close:hover:before {
background: #aaa;
}

.modal__close:before {
transform: rotate(-45deg);
}

@media screen and (max-width: 768px) {

.modal__inner {
width: 90%;
height: 90%;
box-sizing: border-box;
}
}
Sign up to request clarification or add additional context in comments.

Comments

1

Bootstrap has a nice modal screen for this.

Here is a little example. Don't forget to include bootstrap, how to do this is of course to be found on the Bootstrap homepage.

To create a modal, just place this somewhere in your body:

<div id="myModal" class="modal fade">

    <div class="modal-header">
        <!-- Title here -->
    </div>

    <div class="modal-body">
        <!-- Content here -->
    </div>

    <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-primary">OK</button>
        <button type="button" data-dismiss="modal" class="btn">Cancel</button>
    </div>
</div>

And define a button like this:

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch Modal</a>

Comments

0

I suppose that you've already have the page that contains the popup page. For show it like a popup, just create a link in HTML with <a></a> for call a function that opens the popup. Also you don't need to use jQuery; you can use the open() method.

You need to write a code like this:

<script type="text/javascript">
<!--

var style = "status=no, menubar=no, toolbar=no scrollbars=no";

function popup(link)
{
  window.open(link, "", style);
}
//-->
</script>

<a href="javascript:popup('myPage.html')">My link</a>

The style variable defines the style of a classical popup. You can see the complete documentation of open() method on: http://www.w3schools.com/jsref/met_win_open.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.