i'm trying to add two responsive popups in my page but since i'm new in javascript i cant figure out how to modify this code to make it work for both. So far only one works.
html
<div class="container">
<h1>Responsive Popup</h1>
<a id= "popup-trigger1" class="popup-trigger">Open PopUp 1</a>
<a id= "popup-trigger2" class="popup-trigger">Open PopUp 2</a>
</div>
<div class="popup">
<div class="popup-text">This is my popup 1</div>
<span class="popup-btn-close">×</span>
</div>
css
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
position: relative;
}
.popup-trigger { display: block; margin: 0 auto; padding: 20px; max-width: 260px; background: #4EBD79; color: #fff; font-size: 18px; font-weight: 700; text-align:center; text-transform: uppercase; line-height: 24px; cursor: pointer; }
body {
background-color: #E3E3E3;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
height: 240px;
text-align: center;
.container {
max-width: 400px;
margin: 0 auto;
padding: 30px;
text-align: center;
background: white;
border-radius: 10px;
border: 5px solid #9AD3DE;
box-sizing: border-box;
}
}
p {
color: #666666;
margin: 30px auto;
text-align: center;
font-size: 16px;
}
.popup {
background: rgba(100, 100, 100, 0.6);
position: fixed;
display: none;
z-index: 5000;
height: 100%;
width: 100%;
left: 0;
top: 0;
> div {
border-radius: 10px;
position: fixed;
background: #FFFFFF;
box-shadow: 0px 0px 15px 0px rgba(#000000, 0.3);
padding: 30px 15px;
/* Width of popup can be changed */
width: 70%;
max-width: 600px;
z-index: 5001;
#include transform(translate(-50%, -50%));
left: 50%;
top: 50%;
text-align: center;
border: 5px solid #9AD3DE;
}
}
.popup {
background: rgba(100, 100, 100, 0.6);
position: fixed;
display: none;
z-index: 5000;
height: 100%;
width: 100%;
left: 0;
top: 0;
}
.popup > div {
border-radius: 10px;
position: fixed;
background: #FFFFFF;
box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.3);
padding: 30px 15px;
/* Width of popup can be changed */
width: 70%;
max-width: 600px;
z-index: 5001;
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
left: 50%;
top: 50%;
text-align: left;
border: 5px solid #f28920;
}
.popup-btn-close {
position: absolute;
background-color: #f28920;
color:white;
top: -15px;
right: -15px;
border-radius: 50%;
width: 30px;
height: 30px;
line-height:30px;
text-align:center;
font-size:20px;
font-weight:bold;
font-family:'Arial Black', Arial, sans-serif;
cursor:pointer;
-webkit-box-shadow: -4px -2px 6px 0px rgba(0,0,0,0.1);
-moz-box-shadow: -4px -2px 6px 0px rgba(0,0,0,0.1);
box-shadow: -3px 1px 6px 0px rgba(0,0,0,0.1);
}
.popup-btn-close:hover {
background-color: #ac5918;
color: #fff;
}
.popup-text {background: #fff; color: #333; font-size: 19px; line-height: 30px; z-index: 9999;}
# Javascript#
function popupOpenClose(popup) {
/* Add div inside popup for layout if one doesn't exist */
if ($(".wrapper").length == 0){
$(popup).wrapInner("<div class='wrapper'></div>");
}
/* Open popup */
$(popup).show();
/* Close popup if user clicks on background */
$(popup).click(function(e) {
if ( e.target == this ) {
if ($(popup).is(':visible')) {
$(popup).hide();
}
}
});
/* Close popup and remove errors if user clicks on cancel or close
buttons */
$(popup).find(".popup-btn-close").on("click", function() {
if ($(".formElementError").is(':visible')) {
$(".formElementError").remove();
}
$(popup).hide();
});
}
$(document).ready(function () {
$("#popup-trigger1").on("click", function() {
popupOpenClose($(".popup"));
});
});
This is my codepen Codepen
Your help willlll be so much appreciated.
Thank you very much!
krystel
Here is one way to have separate popups. I added another popup div, gave them unique ids, then created a data-target attribute on the triggers. I changed the trigger to work on everything that has a popup-trigger class, and then made a tweak to the wrapper code so that it will create a wrapper in the current popup rather than checking if ANY wrapper exists.
There is also a memory leak because every time you open a popup, you attach more event handlers instead of only attaching them once. I would highly recommend you rework them to avoid issues down the road. Convert them to global events on the document rather than per-popup. I did not change them below as I wanted a minimal change set so you could see what was necessary for your question.
function popupOpenClose(popup) {
/* Add div inside popup for layout if one doesn't exist */
if ($(".wrapper", popup).length == 0) {
$(popup).wrapInner("<div class='wrapper'></div>");
}
/* Open popup */
$(popup).show();
/* Close popup if user clicks on background */
$(popup).click(function(e) {
if (e.target == this) {
if ($(popup).is(':visible')) {
$(popup).hide();
}
}
});
/* Close popup and remove errors if user clicks on cancel or close buttons */
$(popup).find(".popup-btn-close").on("click", function() {
if ($(".formElementError").is(':visible')) {
$(".formElementError").remove();
}
$(popup).hide();
});
}
$(document).ready(function() {
$(".popup-trigger").on("click", function() {
var target = $(this).data('target');
popupOpenClose($(target));
});
});
/* this was actually some kind of LESS or SASS/SCSS originally.
I just stripped out the unnecessary parts, but no changes were necessary */
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
position: relative;
}
.popup-trigger {
display: block;
margin: 0 auto;
padding: 20px;
max-width: 260px;
background: #4EBD79;
color: #fff;
font-size: 18px;
font-weight: 700;
text-align: center;
text-transform: uppercase;
line-height: 24px;
cursor: pointer;
}
body {
background-color: #E3E3E3;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
height: 240px;
text-align: center;
}
h1,
p,
h2,
button {
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 100;
letter-spacing: 0.5px;
}
h1 {
font-size: 40px;
text-align: center;
color: #666666;
margin: 0 0 30px 0;
}
p {
color: #666666;
margin: 30px auto;
text-align: center;
font-size: 16px;
}
.popup {
background: rgba(100, 100, 100, 0.6);
position: fixed;
display: none;
z-index: 5000;
height: 100%;
width: 100%;
left: 0;
top: 0;
}
.popup>div {
border-radius: 10px;
position: fixed;
background: #FFFFFF;
box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.3);
padding: 30px 15px;
/* Width of popup can be changed */
width: 70%;
max-width: 600px;
z-index: 5001;
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
left: 50%;
top: 50%;
text-align: left;
border: 5px solid #f28920;
}
.popup-btn-close {
position: absolute;
background-color: #f28920;
color: white;
top: -15px;
right: -15px;
border-radius: 50%;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
font-size: 20px;
font-weight: bold;
font-family: 'Arial Black', Arial, sans-serif;
cursor: pointer;
-webkit-box-shadow: -4px -2px 6px 0px rgba(0, 0, 0, 0.1);
-moz-box-shadow: -4px -2px 6px 0px rgba(0, 0, 0, 0.1);
box-shadow: -3px 1px 6px 0px rgba(0, 0, 0, 0.1);
}
.popup-btn-close:hover {
background-color: #ac5918;
color: #fff;
}
.popup-text {
background: #fff;
color: #333;
font-size: 19px;
line-height: 30px;
z-index: 9999;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<h1>Responsive Popup</h1>
<a class="popup-trigger" data-target="#popup1">Open PopUp 1</a>
<a class="popup-trigger" data-target="#popup2">Open PopUp 2</a>
</div>
<div id="popup1" class="popup">
<div class="popup-text">This is my popup 1</div>
<span class="popup-btn-close">×</span>
</div>
<div id="popup2" class="popup">
<div class="popup-text">This is my popup 2</div>
<span class="popup-btn-close">×</span>
</div>
On my Tumblr blog I don't understand why images in Photoset are cut, so we can't see all their height.
For example, one picture is 700px width by 394px height, but what we see is 700px width by 383px height, so 11px are missing !
Here is the page:
http://www.scarabeearchitecture.fr/
Here is the CSS for photos and photoset:
.posts {
width: 100%;
max-width: 1024px;
margin: 0 auto 48px;
background: rgba(0, 0, 0, 0.0);
padding: 0px 0 0;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-o-border-radius: 3px;
-ms-border-radius: 3px;
border-radius: 3px;
}
.posts_inner {
width: 100%;
max-width: 700px;
margin: 0 auto;
padding-bottom: 26px;
word-break: break-word;
}
.chat .posts_inner,
.link .posts_inner {
width: 87%;
max-width: 700px;
margin-left: auto;
margin-right: auto;
}
.audio_inner {
overflow: hidden;
}
.photo .posts_inner,
.video .posts_inner,
.audio .posts_inner,
.quote .posts_inner,
.link .posts_inner {
width: 100%!important;
max-width: 1024px!important;
margin-left: auto;
margin-right: auto;
}
.photo .posts_inner .date,
.video .posts_inner .date,
.audio .posts_inner .date,
.quote .posts_inner .date,
.link .posts_inner .date,
ul.tags {
width: 100%!important;
margin-left: auto;
margin-right: auto;
}
#permalinkpage .posts_inner p {
margin-left: auto;
margin-right: auto;
}
.photoset-grid-lightbox_outer,
.video-grid-lightbox_outer,
.audio-grid-lightbox_outer,
.quote-grid-lightbox_outer,
.link-grid-lightbox_outer,
.video-container {
margin-top: 34px;
}
.quote_outer {
color: #f2f2f2;
text-shadow: none;
font-style: italic;
}
.chat_outer {
margin-top: 16px;
}
.link_outer {
color: #f2f2f2;
text-align: center;
text-shadow: none;
}
.link_outer h2 {
padding-bottom: 0!important;
border-bottom: none!important;
}
.link_outer h2 a {
font-size: 24px!important;
font-weight: normal!important;
color: #f2f2f2!important;
}
.link_outer a {
color: #999999!important;
font-size: 14px!important;
}
.link {
padding-top: 22px;
}
.photoset-grid-lightbox_outer {
padding: 0px;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.25)), to(rgba(0, 0, 0, 0))), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
background: -moz-linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-moz-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-ms-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-o-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
}
.video-grid-lightbox_outer {
padding: 3px 38px 38px;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.25)), to(rgba(0, 0, 0, 0))), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
background: -moz-linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-moz-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-ms-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-o-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
}
.audio-grid-lightbox_outer,
.quote-grid-lightbox_outer {
padding: 38px;
overflow: hidden;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.25)), to(rgba(0, 0, 0, 0))), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
background: -moz-linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-moz-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-ms-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-o-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
}
.link-grid-lightbox_outer {
padding: 44px 38px 58px 38px;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.25)), to(rgba(0, 0, 0, 0))), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
background: -moz-linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%), #333333 url(http://static.tumblr.com/wofln30/tT8myt4ib/bg_noise.png) center;
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-moz-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-ms-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
-o-box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
box-shadow: 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.6) inset;
}
.photoset-grid-lightbox,
.photopost,
.video-container {
position: relative;
z-index: 50;
-webkit-box-shadow: 0 1px 20px gray;
-moz-box-shadow: 0 1px 20px gray;
-ms-box-shadow: 0 1px 20px gray;
-o-box-shadow: 0 1px 20px gray;
box-shadow: 0 1px 20px gray;
background: #000000;
}
.photoset-grid-lightbox:before,
.photopost:before,
.video-container:before {
content: "";
position: absolute;
top: 0;
right: 0;
left: 1px;
z-index: 100;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.photoset-grid-lightbox:after,
.photopost:after,
.video-container:after {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
z-index: 100;
border-left: 1px solid rgba(255, 255, 255, 0.1);
}
.posts h2,
#permalinkpage h2 {
font-size: 28px;
padding-bottom: 18px;
border-bottom: solid 2px rgba(0,0,0,0.04);
}
.posts h2 a {
color: #333333;
font-size: 28px;
}
.sp_show {
display: none;
}
.posts p,
#permalinkpage p {
margin: 30px 0 30px;
font-size: 14px;
}
#media screen and (max-width : 768px){
.posts {
padding: 24px 0 0;
}
.posts_inner {
width: 87%;
margin-left: auto;
margin-right: auto;
}
.photo .posts_inner,
.video .posts_inner {
width: 95%;
}
.photoset-grid-lightbox_outer,
.video-grid-lightbox_outer,
.audio-grid-lightbox_outer,
.quote-grid-lightbox_outer,
.link-grid-lightbox_outer,
.video-container {
margin-top: 24px;
}
.video-grid-lightbox_outer {
padding: 13px 38px 38px;
}
.photo .posts_inner .date,
.video .posts_inner .date {
width: 92%;
margin-left: auto;
margin-right: auto;
}
.posts p,
#permalinkpage p {
font-size: 1.6rem;
}
}
#media screen and (max-width : 480px){
.photoset-grid-lightbox_outer,
.audio-grid-lightbox_outer,
.video-grid-lightbox_outer {
padding: 0;
-webkit-box-shadow: none;
-moz-box-shadow: none;
-o-box-shadow: none;
-ms-box-shadow: none;
box-shadow: none;
background: none;
}
.photoset-grid-lightbox,
.photopost,
.video-container {
-webkit-box-shadow: none;
-moz-box-shadow: none;
-o-box-shadow: none;
-ms-box-shadow: none;
box-shadow: none;
}
.audio-grid-lightbox_outer {
width: 87%;
margin-left: auto;
margin-right: auto;
}
.pc_show {
display: none;
}
.sp_show {
display: inline;
}
.spotify_audio_player {
max-width: 100%!important;
height: 80px!important;
}
}
.posts div.date a,
.posts div.date,
#permalinkpage div.date a,
#permalinkpage div.date {
color: #999999;
font-size: 12px;
font-weight: bold;
}
.posts div.date a:hover {
color: #006bd5;
}
.posts p.date {
margin-bottom: 6px;
text-align: right;
color: #999999;
font-size: 12px;
}
.posts p.date a {
color: #999999;
}
.caption {
width: 100%;
margin: 35px auto 0;
}
.posts .link {
font-size: 12px;
}
I'm running into a very specific issue using CSS triangles:
I've created buttons that work perfectly on desktop browsers (ie9+, ff, chrome, safari), and on iPhones in portrait mode... The issue exists on iPads (retina and non-retina), as well as iPhones in landscape. The button renders with a line between the main container and the css triangle(s) that I've got in place.
Here's a screenshot on imgur:
http://imgur.com/d0k6lP2
Here's the code I'm using:
HTML:
<span>BUTTON SHAPE</span>
CSS (there are potentially a few non-relevant styles included because this is pasted from a larger file):
.cta-watch {
display: inline-block;
position: relative;
padding: 0 10px;
background-color: #91a1a8;
border-collapse: collapse;
color: white;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-style: normal;
letter-spacing: 2px;
font-weight: 400;
font-size: 30px;
letter-spacing: 2px;
text-transform: uppercase;
line-height: 40px;
text-decoration: none;
transform: rotate(360deg);
}
.cta-watch.large {
display: inline-block;
position: relative;
width: 34px;
height: 32px;
}
.cta-watch.large:hover {
text-decoration: none;
}
.cta-watch.large.arrow-left::after, .cta-watch.large.arrow-right::after {
border-left: none;
border-right: none;
}
.cta-watch.large span {
display: inline-block;
width: 0;
height: 0;
text-indent: -99999px;
}
.cta-watch.large span:before {
width: 0;
height: 0;
content: '';
border-color: transparent transparent #91a1a8 transparent;
border-width: 0 27px 14px 27px;
border-style: solid;
position: absolute;
top: -14px;
left: 0;
}
.cta-watch.large span:after {
width: 0;
height: 0;
content: '';
border-color: #91a1a8 transparent transparent transparent;
border-width: 14px 27px 0 27px;
border-style: solid;
position: absolute;
bottom: -14px;
left: 0;
}
.cta-watch.large:before {
display: block;
width: 100%;
height: 0;
content: '\25BA';
color: white;
font-family: arial, "Helvetica Neue", Helvetica, sans-serif;
margin-left: 3px;
font-size: 22px;
line-height: 34px;
text-align: center;
}
JSBin showing code demo here: http://jsbin.com/ocaGeja/1
Any help would be greatly appreciated - Thank you!
I can reproduce the same issue in Chrome for Windows, changing the zoom level.
At least in this situation, it is solved changing this value to decimal:
.cta-watch.large span:before {
...
top: -13.7px;
May be that can help you ?
Another posibility would be to change the way you create the hexagon. Instead of the triangles way, you can try the multi-background way:
.hexagon {
position: absolute;
left: 20px;
top: 20px;
font-size: 80px;
height: 2em;
width: 1.732em;
background-size: 50.5% 50.5%;
background-image: -webkit-linear-gradient(300deg,transparent 33%, red 0%), -webkit-linear-gradient(240deg,transparent 33%, red 0%), -webkit-linear-gradient(60deg,transparent 33%, red 0%), -webkit-linear-gradient(120deg,transparent 33%, red 0%);
background-repeat: no-repeat;
background-position: top left, top right, bottom left, bottom right;
}
It's responsive em based, so that it can fit your need quite well.
demo