Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 585213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:58:46+00:00 2026-05-13T14:58:46+00:00

Easy All As I’ve been learning jQuery lately, I decided to write my own

  • 0

Easy All

As I’ve been learning jQuery lately, I decided to write my own modal window to play videos in, when the video thumbnail is clicked. It all works fine, but I’m just wondering how could I turn it into a plugin, so I could use it on different pages with different parameters etc. I read the documentation, and a few tutorials, but I can’t seem to get it working. My basic code is as follows:

<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){

    // Add our click OPEN event
    $j("a.video_link").click(function (e) {
        e.preventDefault();
        // Add our overlay div
        $j('body').append('<div id="overlay" />');
        // Fade in overlay
        $j('#overlay').css({"display":"block","opacity":"0"}).animate({"opacity":"0.2"}, 300),
        // Animate our modal window into view
        $j('#video').css({"top":"43%"}).css({"opacity":"0"}).show().animate({"top": "50%", "opacity": "1"}, 550),
        // Add our close image
        $j('#video').append('<div id="modal-vid-close" title="Close window" />');
        // Add our click CLOSE event
        $j('#overlay, #modal-vid-close').click(function () {
            //Animate our modal window out of view
            $j('#video').animate({"top": "55%", "opacity": "0"}, 350).fadeOut(200),
            // Fade out and remove our overlay
            $j('#overlay').fadeOut(200, function () { $j(this).remove(); $j('#modal-vid-close').remove()} )
        });
    });
});

I’d like to turn this into a plugin so I can use it on different pages, and just specify the ‘trigger’ link, and the div id to show in the window (it will already be loaded on the page, but hidden). Something like this, added to doc load on each page:

var trigger = $j('.video_container a');
var modalcontent = $j('#video');

Any help, or pointers to good tutorials, much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:58:46+00:00Added an answer on May 13, 2026 at 2:58 pm

    Here’s a good template, which I found on a tutorial site, Queness:

    (function($){
        $.fn.extend({
            // change 'pluginname' to your plugin name (duh)
            pluginname: function(options) {
    
                // options for the plugin
                var defaults = {
                    width: 500,
                    height: 300
                }
    
                var options =  $.extend(defaults, options);
    
                return this.each(function() {
                    // main code goes here, will apply to each element of $(this)
                    // e.g. `$(this).click( function() {} )`
                    // also have access to `options` i.e. `options.width`
                });
            }
        });
    })(jQuery);
    

    Then put this in your HTML:

    <script type="text/javascript">
    $(document).ready( function() {
        // use default options
        $('.selector').pluginname();
        // custom options
        $('.selector').pluginname({width:300, height:200});
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The subject says it all - normally easy and cross platform way is to
First of all, I'm fairly sure snapping to grid is fairly easy, however I've
I do this all the time using VNC and it is very easy, but
Is there an easy way to do a GROUP BY DATE(timestamp) that includes all
The question says it all! I am looking for an easy to use alternative
An easy jQuery question. I have several identical forms ( except their name )
Easy question this time. I'm trying to test whether or not a string does
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
Is there an easy way to iterate over an associative array of this structure
Is there an easy way in C# to create Ordinals for a number? For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.