When the user first scrolls down, a popup will appear. However, if they scroll down a second time,

I'm attempting to create a popup that appears when the user scrolls down to a certain point. The code for this functionality is working well and is provided below.

<div id="spopup" style="display: none;" class="news_sletter">
    <a style="position: absolute; top: 7px; right: 10px; color: #555; font-size: 10px; font-weight: bold;" href="javascript:void(0);" onclick="return closeSPopup();">
        <img src="images/ico-x.png" width="18" height="18" style="background: #fff;" />
    </a>
    <div class="side_bar_sub_heading">
        <h6>Newsletter </h6>
    </div>

    <p>Subscribe to our email newsletter for useful tips and resources.</p>

    <form>
        <div class="form-group blog_form">
            <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email Address">
        </div>

        <div class="search_btn-3">
            <button class="btn btn-default" type="submit">Subscribe </button>
        </div>
    </form>

</div>

The jQuery code is as follows:

<script>
 var isAlreadyPopUp = true;

$(window).scroll(function () {
    if(!isAlreadyPopUp){
            if ($(document).scrollTop() >= $(document).height() / 25)
        $("#spopup").show("slow"); else $("#spopup").hide("slow");
     }
});
function closeSPopup() {
    $('#spopup').hide('slow');
}
</script>

And here is the CSS:

<style type="text/css">
    /* popup css*/
    #spopup {
        background: hsl(0, 0%, 0%) none repeat scroll 0 0;
        border-radius: 9px;
        -moz-border-radius: 9px;
        -webkit-border-radius: 9px;
        -moz-box-shadow: inset 0 0 3px #333;
        -webkit-box-shadow: inset 0 0 3px #333;
        box-shadow: inner 0 0 3px #333;
        padding: 27px;
        width: 300px;
        position: fixed;
        left: 40%;
        display: none;
        z-index: 10;
        margin-bottom: 40px;
        text-align: center;
    }
</style>

If a user decides not to subscribe and clicks the close button, the popup will successfully close. However, after five or ten minutes, we want the popup to automatically reappear. Can someone please assist with this?

Any help would be appreciated.

Answer №1

To create a global variable, follow these steps:

var isNewVariable;

Assign the value of 'true' or 'false' to the variable based on your requirements. For instance:

isNewVariable=true;

You can then check the value of isNewVariable and decide whether to execute your popup display code.

$(window).scroll(function () {
        if(!isNewVariable){
                if ($(document).scrollTop() >= $(document).height() / 25)
            $("#popup").show("slow"); else $("#popup").hide("slow");
         }
    });
    function closePopup() {
        $('#popup').hide('slow');
 }

Note:

For automatic popup opening after a set time interval, you can utilize the setTimeout function as shown below.

setTimeout(function(){ alert("Hello"); }, 3000);

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

Trouble with retrieving JSON data?

Struggling to access the JSON object issue: Received JSON Object: {"71":"Heart XXX","76":"No Heart YYYY"} I attempted to retrieve values for 71 and 72 individually but encountered compile time problems as: Syntax error on token ".71", delete this token ...

Jest tests are failing because React is not defined

I am attempting to implement unit tests using Jest and React Testing Library in my code. However, I have encountered an issue where the tests are failing due to the React variable being undefined. Below is my configuration: const { pathsToModuleNameMapper ...

What is the best way to retrieve data from multiple pages of a JSON API in one go?

Why am I only receiving the first page out of 61 pages in this json file with my current call? How can I retrieve all of them? Is there a way to use axios in a loop or another method? <template> <div id="app"> <the ...

Issues arise when trying to use the Jquery append() method in conjunction with Angular

We are currently utilizing jquery version 1.9.1 and angular version 1.2.13 for our project. Our wysiwyg editor is functioning well, as we are able to save HTML into the database and load it back using the jquery append function successfully. However, we ar ...

Generating live link for iteration using ng-repeat

I am currently facing an issue with my table of content in the tableofcontent.html file. Each article title is clickable, but when I click on a link, the data does not populate correctly in the articles.html page. How can I ensure that the data for each li ...

Having trouble setting the InnerHTML property of Null on my Ionic app, what could be the issue?

I'm working on a code to display the remaining time for generating a random code in the DOM. var count = setInterval(function () { var date = new Date(); var currentSecond = date.getSeconds(); ...

Encountering difficulties sending modified object values to Node/Express in JavaScript

I am currently working on a project that involves fetching specific stock data from Yahoo Finance based on the user's selection and then transmitting this data to a Node/Express server. ISSUE: Despite everything else functioning correctly, the Node/E ...

Managing the scrolling direction horizontally with waypoints.js

As I work on creating a custom wizard form with waypoints, I've encountered an interesting issue that has left me puzzled. In my sample CODEPEN, you can see two pages of the wizard process to better understand the problem. Upon clicking the forward ...

Mobile browsers experiencing issues with playing HTML5 videos

Having trouble with HTML5 Video not working on my mobile device? I've encountered several issues when trying to load videos on my mobile browsers. When I attempted to remove controls, the video wouldn't show up on the mobile browser at all. Addin ...

Change this time record into a standard date

"usage_timestamp": [13308678945000000] I am trying to convert this unique timestamp format found in my JSON file into a normal date using Node.js. Can anyone help me with the proper conversion process? It seems like this is not your typical Uni ...

Can a React component be configured to show only a specific array key when returning an array?

Just diving into the world of react and experimenting with different approaches to understand how I can transition into this new architecture. Currently, I have a basic component where I am returning an array of elements (mainly for testing purposes): cl ...

Is it possible that the Facebook like button is not functioning properly due to being initialized with jQuery?

I'm currently in the process of implementing the Facebook SDK on my website by following this step-by-step guide. After checking the console, I am pleased to report that there are no errors present. $(document).ready(function(){ $.ajaxSetup({ cache ...

Creating a web application that uses AJAX and smoothly degrades if the browser does not support JavaScript

Apologies for the lengthy title, but my main focus is on creating an ajax-based application. I currently have a version one of this app that operates without requiring javascript. I am looking to upgrade it to utilize ajax for accessing resources from a t ...

Struggling to Obtain File Path in PhoneGap for iOS

I am currently working on creating a file that I would like to attach to an email using the de.appplant.cordova.plugin.email-composer plugin. Although the email composer pops up and shows the file icon as if it is attached, the console displays the followi ...

Locate any identical elements within an array and substitute them with their corresponding frequency

Let's say I have an array that looks like this: arr = [25, 25, 25, 20, 15, 10, 10, 5]; My goal is to count the number of duplicate values (for example, three 25s and two 10s) and create a new array that would look like this: newArr = ['25 * 3& ...

Firebase Client v9 (npm) experiencing issues with imports

Situation: After finally taking the initiative to update the Firebase library in my app from 9.0.2 compat to the new modular, tree-shakable library, I encountered some issues. Using Windows 10 and WebStorm, my package.json only contains the dependency { " ...

Tips for showing a form's help text when manually rendering fields in Django forms?

In my Forms.py file, I have the following code snippet: class CustomerForm(forms.Form): name = forms.CharField(max_length=255,required=True,validators=[alphaonly],help_text="Enter your name") I am attempting to render it in an HTML format like ...

Changing div height based on the height of another dynamic div

Looking to create a box that matches the height of the entire page, live height minus another dynamic div called #wrapping. I have code that offsets it instead of removing the height of the div... function adjustBoxHeight() { var viewPortHeight = $(wind ...

What is the process of incorporating CSS into XML files?

My goal is to implement an embedded bar-code font via CSS in an XML file. The XML file provides order numbers that I want to visually represent as a barcode. Once this document is sent via email, it automatically generates a sales invoice. This snippet g ...

a container holding two floating divs

I have been attempting to create two divs positioned side by side, with one containing content and the other acting as a sidebar. Both of these divs are contained within another larger container div. Despite my efforts, I have not been successful in achiev ...