Coder Social home page Coder Social logo

xgqfrms-github / jquery-interstitial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brettdewoody/jquery-interstitial

0.0 1.0 0.0 95 KB

A jQuery plugin for creating interstitial popups. The popup creates an semi-transparent overlay on the page, then opens a URL of your choice on top - an ad, form, etc.

CSS 20.66% JavaScript 79.34%

jquery-interstitial's Introduction

A jQuery utility plugin for creating interstitial overlays.

When called a transparent overlay will gray out your site and the content from the URL will appear over top in the center of the screen. Clicking anywhere outside the popup will cause the interstitial to fade away and reveal the site again.  It's also possible to close the interstitial with a link.

## Usage ##

    <link href="jquery.interstitial.css" rel="stylesheet" type="text/css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script> 
    <script src="jquery.interstitial.min.js" type="text/javascript"></script>
    <script type="text/javascript">
	 $(document).ready(function(){
           $().interstitial('open', {
              'url' : 'popup.html'
            });
         });
     </script>

     The above will fade out the site and display popup.html on top.


## Options ##
     
     'url'                        : ''                                                    // The URL of the popup file
     'width'                    : 600                                                // The width of the popup
     'height'                   : 400                                                // The height of the popup
     'opacity'                 : 70                                                  // The opacity of the overlay 
     'id'                         : 'popupBlock'                                    // The ID of the popup's wrapper div
     'onInterstitialClose' : function() {FUNCTION NAME}           // A function to run when the interstitial is closed


## Closing the interstital ##

The interstitial will close when the user clicks outside the popup. It can also be closed using the interstitial('close') method. To create a 'close' link you would do this:

     <a href="#" onClick="javascript:$().interstitial('close'); return false">Close</a>

If you have set an onInterstitialClose callback function it will be run when the interstitial is closed.


## Using a callback function ##

If you would like to call a function or run some code when the interstitial is closed you can use the onInterstitialClose callback function. To do this, set your callback function in the options, like this:

      <script type="text/javascript">
	 $(document).ready(function(){
           $().interstitial('open', {
              'url' : 'popup.html',
              'onInterstitialClose' : function() {myCallbackFunction();}
            });

            function myCallbackFunction() {
              // Run your code here
            }
         });
     </script>

When the user closes the interstitial your myCallbackFunction will run.


## Use with jquery.cookie.js ##

If you would like to display the interstitial only sometimes (once per session, week, etc) you can easily combine jquery.interstitial with the jQuery Cookie plugin (https://github.com/carhartl/jquery-cookie).  If you wanted to display your interstitial to users on just the first visit to your website you could use the following:

     if (!$.cookie('COOKIE NAME')) {
	  $().interstitial('open', {
               'url'     : 'popup.html'
           }); 
	  
	  //Create a cookie
	  $.cookie('COOKIE NAME', 'viewed', {expires: -1, path: '/'});
	}

jquery-interstitial's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.