trouble concerning the responsiveness of a jQuery popup

Hello, I am trying to create a responsive login popup using jQuery but have been struggling for a week. Below is the code snippet that I have been working on. Any help or guidance would be greatly appreciated.

//scriptLogin.js archive

$(document).ready(function() {
$('a.login-window').click(function() {
    
    //Get values of variables from the link
    var loginBox = $(this).attr('href');

    //Create the popup
    $(loginBox).fadeIn(300);
    
    //Set padding + border (css)
    var popMargTop = ($(loginBox).height() + 24) / 2; 
    var popMargLeft = ($(loginBox).width() + 24) / 2; 
    
    $(loginBox).css({ 
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    
    //Add mask layer to body (to darken background when popup opens)
    $('body').append('<div id="mask"></div>');
    $('#mask').fadeIn(300);
    
    return false;
});

//Close the popup when X icon is clicked
$('a.close, #mask').live('click', function() { 
  $('#mask , .login-popup').fadeOut(300 , function() {
    $('#mask').remove();  
}); 
return false;
});
});
/*LOGIN*/
@media only screen and (max-width: 600px) {
 .login-popup{
     width:100%;
  }
}

#login-box{
width:600px;
height:auto;
}

.login-popup{
display:none;
background:#2c3338;
padding:10px;
border:2px solid #000;
float:left;
font-size:1.2em;
position:fixed;
top:40%;
left:50%;
z-index:99999;
color:#606468;
font-family:'Calibri';
line-height:1.5em;
}

[...more CSS and HTML code here...]

</head>
<body>
<div>
<header>
        <nav role="navigation" class="noround navbar-inverse">
            <div class="navbar-header">

[...more HTML code here...]

</header>
      
    [...more code that isn't important..]
  
</div>
<script src="js/jquery-1.12.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/scriptLogin.js"></script>
</body>
</html>

Answer №1

Utilizing bootstrap? Bootstrap has a responsive pop as well, check it out

http://getbootstrap.com/javascript/

If you're interested in our custom code for a responsive pop, take a look here. I've written some simple code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.pop_div{ display:none;}
.overrelay{ display:none;}
.pop_div {
    position: relative;
    margin: 0 auto;
    width: 38%;
    padding: 20px;
    background: rgba(247, 247, 95, 0.42);
    border: 1px solid #ccc;
    z-index: 12;

}
.close_pop {
    float: right;
    background: #f00;
    padding: 7px;
    border: hidden;
    height: 20px;
    width: 20px;
    line-height: 9px;
    border-radius: 10px;
    text-align: center;
    color: #fff;
}
.overrelay {
    position: absolute;
    top: 0px;
    background: rgba(255, 0, 0, 0.25);
    right: 0px;
    bottom: 0px;
    left: 0px;
    z-index: 10;
}
</style>
</head>

<body>
     <div class="responsive_pop">Click me for Responsive POP </div>
     <!---------/// POP HERE ------->
      <div class="pop_div">
           <div class="close_pop">X</div>
         <form>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

      </div>
      <div class="overrelay"></div>
     <!--------/// POP HERE --------->

</body>
  <script>
     $('.responsive_pop').click(function(){

           $('.pop_div').show(500);
           $('.overrelay').show(500);



         });

         $('.close_pop').click(function(){

              $('.pop_div').hide(500);
           $('.overrelay').hide(500);

             });
  </script>
</html>

Answer №2

@media screen and (max-width: 600px) {
 .pop-up-login{
     width:100%;
     position: absolute;
     bottom: 0;
  }
}

Make sure to place this code at the end of your CSS file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dual Camera Toggle Functionality with Three.js Orbit Controls

I am facing an issue with two cameras in one scene, one viewport, and one renderer. I switch between cameras using HTML buttons. ISSUES Issue 1 When using camera1, there is no response from moving the mouse. However, when I switch to camera2, the orbit ...

Input form sending information to an incorrect destination URL

I'm struggling to get my form to pass a parameter to a link in the desired format: index.php?action=2&parameter=value Currently, it is only passing the parameter like this: index.php?parameter=value Here's the code I have been using : &l ...

Issues with jQuery toggle functionality have been reported specifically on the iPhone8 and other iOS devices

Hi everyone, I'm facing an issue with the header on my website. It displays a hamburger menu on small screens, and while it works perfectly on PCs and Android phones, it's unresponsive on iOS, specifically on my iPhone 8. I've tried using va ...

Having trouble with `request.auth.session.set(user_info)` in HapiJS?

I've encountered an issue with my strategy that is defined on a server.register(). Although I followed a tutorial, the code seems to be copied verbatim from it and now it's not functioning as expected. server.auth.strategy('standard&apo ...

Using async/await with recursion in NodeJS for handling express requests

My code contains a function named GetAllData() that triggers the GetPurchaseData function, which in turn calls itself recursively until all the data is loaded. async function GetAllData(){ console.log("starting loading purchase data"); await G ...

Hover and focus effects of the main navigation menu in Semantic UI CSS

I seem to be having trouble styling my navbar with semantic-ui. I want to make changes to the color and background-color on hover and when focused. However, no matter what I try, the hover effect just won't work. I was only able to achieve it using jQ ...

Utilizing the CSS grid framework to efficiently create repetitive rows and columns in code

When I work with CSS frameworks like Bootstrap or Materialize, I often find myself repeatedly typing the same HTML code: <div class="row"> <div class="col s12"> <!-- Some text/ a button / something --> </div> </d ...

propagate the previous state using a variable

Currently, I am in the process of refactoring a codebase but have hit a roadblock. My main aim is to update the state when the onChange event of a select box occurs. Specifically, the parameter searchCriteria in my handleFilterChange function is set to in ...

Implementing CSS in Laravel 8

After placing my CSS file in the public/css folder, I included it in the head section with the following code. <link href="{{ url('/css/app.css') }}" rel="stylesheet"> Unfortunately, the CSS styles are not being applied ...

Smooth-scroll plugin does not activate active state (due to JS modification)

I'm currently facing an issue with a script that handles smooth scrolling and the active state on my main navigation. The plugin in question can be found at: It's important to note that the navigation bar is fixed and therefore has no height. T ...

Track and display the number of times a button is clicked using

I'm looking to create a button click counter that changes the text on the button when clicked. I want to write this information to a database as well, but I'm struggling with the implementation. <button type="button" class="btn btn-info" styl ...

Issue with ReactJS on the server side rendering

Could someone please help me understand my current issue? On the server side (using Node.js), I have the following code: var React = require('react'); var ReactDOMServer = require('react-dom/server'); var TestComponent = React.create ...

NPM repository that is not accessible online

I have been looking into creating my own private NPM mirror/repository, but I'm not sure where to start. My objective is to create a repository within my private network that contains all the latest free NPM packages available on the NPM website. I w ...

The Gatsby node encounters an error while trying to create a new page

I am currently working on creating sub-pages for a projects category in Gatsby. The parent page for each project is generating correctly, but the sub-pages are not behaving as expected. Each project has the potential to have zero or multiple sub-pages, an ...

What could be causing the connection failure between my MongoDB and Node.js?

Hello there! This is my first time posting a question on Stack Overflow. I've been attempting to connect my application to MongoDB. Despite successfully connecting to the server, I am facing issues with the MongoDB connection. I have double-checked ...

Choosing a radio button based on the stored value within a variable

When transferring a variable (active) from my route to EJS, I initially found it easy to simply display its value: <!-- Active Text Input--> <div class="form-outline mb-4"> <label for="active" class="form-label">Active</label> ...

Creating a grid UI in AngularJS using Typescript: utilizing functions as column values

I am working on an AngularJS app that includes the following UI grid: this.resultGrid = { enableRowSelection: true, enableRowHeaderSelection: false, enableHorizontalScrollbar: 0, enableSorting: true, columnDefs: [ { name: &apos ...

HTML does not support the use of certain symbols

Currently, I am in the process of designing a homepage for my school project. However, I have run into an issue. The content that I want to be displayed on my homepage is as follows: "Daudzspēlētāju tiešsaites lomu spēle (Massively Multiplayer Online ...

Generate SVG components without displaying them

Is there a way to generate a custom SVG graphic through a function without the need to attach it to any element? Can I simply create an empty selection and return that instead? Here is my current implementation: function makeGraphic(svgParent) { retur ...

multiples of order quantities in WooCommerce

In order to implement a minimum order quantity based on category, I came across this code. However, it seems to apply to all products in the cart. What additional modifications would be needed to specify certain categories? My objective is for customers t ...