Weblosofia com CSS, Jquery, Javascript, Ajax, PHP etc.
por Alexandre Magno
Postado em Março 23rd, 2008 por Alexandre Magno
Este plugin centraliza qualquer elemento através do método CSS da margem negativa.
Sem nenhum argumento, o método do plugin cetraliza horizontalmente e verticalmente.
$("class_or_id").center();
$("class_or_id").center({ horizontal: false // somente vertical }); $("class_or_id").center({ vertical: false //somente horizontal });
http://plugins.jquery.com/project/elementcenter
Este plugin foi testado no IE 6, IE 7, Safari 3, Firefox 2.0
* Não funcionou no Firefox 3.0 e no Google Chrome. Estou tendo dor de cabeças com os dois ultimamente. Para mim uma grande decepção. Muitos Javascript estão lentos, assim como o Flash.
Irei trabalhar em uma próxima versão usando integralmente o Dimensions, que funciona muito bem.
Este plugin requer o Dimensions plugin para funcionar corretamente
http://www.alexandremagno.net/jquery/plugins/center
http://code.google.com/p/jquerydevbrazil/wiki/jQueryCenterPlugin
http://code.google.com/p/jquerydevbrazil/downloads/list
Alexandre Magno - http://www.alexandremagno.net
Tales comentou:
24th Março, 2008 às 10:53 am
Boa Alex!
A maioria dos desenvolvedores HTML/CSS precisam centralizar elementos. Bem prático e fácil de usar o plugin.
Parabéns! :>)
john comentou:
26th Março, 2008 às 2:50 am
Hi, I came across your plugin looks good. I have a question of why you chose GPL over MIT or BSD license for a simple utility. Using the gpl will cause people pass over it since it would require them to license all of their code under the gpl.
Good work by the way.
admin comentou:
26th Março, 2008 às 9:42 am
Good point John. After a research I moved to MIT license. I would like the orientation to how I can put my plugins in jQuery plugins repository…
Very thanks…
h0tzen comentou:
3rd Abril, 2008 às 3:54 pm
you have to add return this; to make the center()-method chainable!
admin comentou:
4th Abril, 2008 às 9:56 am
Take a look hotzen:
http://code.google.com/p/jquerydevbrazil/source/browse/trunk/jquery.center.js
I made the change… thanks for suggestion!
nuno comentou:
14th Abril, 2008 às 11:33 am
okay, mais uma vez subiste na minha consideração
um grande abraço and good dev
Wilton José comentou:
2nd Julho, 2008 às 2:26 pm
Muito bom o seu plugin estou usando e está funcionando bem no IE 6/7 e no firefox 2. Já no firefox 3 ele não funciona legal. Testei no Ubuntu 8.04 com o firefox 3.
[]s
Wilton
Alexandre Magno comentou:
24th Setembro, 2008 às 5:28 pm
@Wilton: Olá Wilton, infelizmente para cada novo browser mudanças precisam ser feitas, estou trabalhando nisto. Obrigado!
jquery plugins by name « Web Developer comentou:
20th Fevereiro, 2009 às 1:57 am
[…] portuguese page can be found at: http://www.alexandremagno.net/blog/?p=75 […]
Rafael comentou:
7th Abril, 2009 às 8:47 pm
Alexandre,
alguma luz em relação ao ff3 ?
qual o problema q voce está tendo ? talvez eu possa ajudar.
vlw !
PEPE MUJICA comentou:
11th Julho, 2009 às 5:57 pm
Hola, muy buen plugin, lástima que no anda con FF3 ![]()
Alexandre Magno comentou:
13th Julho, 2009 às 1:38 am
@Pepe: Irei descobrir o que está havendo, pois ele não foi atualizado desde o Firefox 2. Gracias…
LouGee comentou:
15th Outubro, 2009 às 12:43 pm
Hi,
I really think this plugin works great! I have a question though…
The plugin centers(veritical) the element by computing the page’s height and not the screen’s?
Alexandre Magno comentou:
15th Outubro, 2009 às 2:29 pm
@LouGee: Thanks for enjoy it! I’m working on improvements, but it gives a lot of headache to make work in all browsers. The plugin center vertically computing the page height. I hope it helps…
LouGee comentou:
15th Outubro, 2009 às 7:10 pm
Thank you for this plugin. I’m using it now on my client’s website ^_^
Thank you thank you thank you!
imKarl comentou:
25th Novembro, 2009 às 4:03 pm
Hi Alexandre, I can use free this plugin on proyect of comerce?
imKarl comentou:
25th Novembro, 2009 às 4:06 pm
Ohhh sorry, and realy this plugin is so very good, thanks for this contribution.-
Best regards.
Alexandre Magno comentou:
25th Novembro, 2009 às 11:02 pm
@imKarl: sure that you can. This plugin is out of date, I`m working with a new version fully tested…
imKarl comentou:
26th Novembro, 2009 às 1:35 am
Great thanks, I testing this version on: IE8, FF 3+, Chrome 3+, SF 4+ and don’t problem with one.-
Alexandre Magno comentou:
26th Novembro, 2009 às 4:06 pm
@imKarl. Great! Some people report bugs, it seens that you are using in simple situations, because in new version I’m dealing with padding, marging, diferent scenarios to make work in all cases, but if you’re not having problem it’s great!
stawka comentou:
26th Janeiro, 2010 às 8:49 am
Hi!
You should consider adding scrollTop() and scrollLeft() values, beacause when the element is in body, it is centered relative to the window size. When page is scrolled down f.ex. 2 times window height, centered div is unvisible, because it is at the top of page, not at the visible center.
Best regards!
Alexandre Magno comentou:
26th Janeiro, 2010 às 9:07 am
@stawka: thanks for the tip! I’m refactoring the plugin to work in some cases like this and this is a golden tip…
Os seguintes campos estão incorretos ou faltando