jQuery - How Do I Place a DIV On Overlay?

廉价感情. 提交于 2019-12-03 05:11:25

See this quick demo here, the key lies to the modal being absolute over the top of the opaque background. The demo dynamically adds the background overlay div and the modal div to the body but you could define these in the html and just show them.

Agreed there is no need to use a plugin for a modal effect, most of the plugins come with lots of options hence the bloat which you do not want if you only need the simplest of effects. - Note we can do this in two lines rather than 3 - and without a plugin!!

Also it is far easier to define css classes and add these rather than add inline styles to an element in script. Easier to maintain.

Jennifer

I think your best solution might be to use a jquery plugin. A quick google search threw up this: http://www.ericmmartin.com/simplemodal/ which is doing what you need in three lines!

If you want some more, there are loads on the jquery overlays plugin page

From the look of it, the CSS is the key to getting things right, and most of these examples should come with demo CSS for you to adapt.

Obviously this brings in more external jquery code which you are concerned about - but I would suggest a well written and stable plugin would save you lots of work/time/lines of code!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!