I have tried almost all of the jQuery Modal plugins I can find on the net but they are all much to bulky for what I need. I don't need all the fancy features, I want to be able to open a div and have the background of the page go transparent grey like the photo below and have my div be on top of it, that is all I need to do so I would like to write some jQuery to do this instead of using a bulky plugin. Does anyone have any small code that can do this task? Is the transparent background an image or just CSS?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Adding a timeout to a render function in ReactJS
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
To name another plugin for this task is nyromodal which I find easy to use but still offers a lot of setting options if you should find yourself in the need for that (later)
You can use jQuery UI which has a dialog plugin that supports modal .. http://jqueryui.com/demos/dialog/#modal
Alternatively you would create a div that spans the whole viewport in size, set its opacity to 50% (0.5) and also catch and stop all events to make it modal. Then display your div on top of it ..
I've been using the jQuery UI Dialog for this. http://jqueryui.com/
You can create a simple modal using pure HTML and css,no need of javascript and jquery,which will indirectly reduce time and work.
visit this.
This is what I use myself; it looks nice, the code is simple and easy to understand, and uses minimal CSS and jQuery.
Here is the code (And a fiddle to see it in action: http://jsfiddle.net/cadkJ/125/):
HTML
CSS
jQuery
Do you want to lock scrolling?
Add the following CSS rule:
Replace the jQuery function with: (
body
added to line 3)Do you want to prevent click events on the background from closing the modal?
Replace the jQuery function with: (
#modal-background
removed from line 2)EDIT: This is obviously outdated. So please refer to Andrew Odri post below.
I don't know how good you are in CSS and JavaScript, but your request shouldn't be that hard to do yourself.
I haven't tested the code, might not work, but you'll get the idea.