Maison > php教程 > php手册 > le corps du texte

PHP、jQ和CSS制作头像登录窗

WBOY
Libérer: 2016-06-13 11:14:49
original
859 Les gens l'ont consulté

我设计了一个简单有趣的包含Gravatar头像的登录框功能,头像是基于邮件id从gravatar.com导出的。这篇文章是非常基本的层面上的CSS实现和几行Jquery和PHP代码。我希望这个登录框设计对您的web项目给出了一些特殊的味道。在尝试这个示例前请在Gravatar上先上传你的头像.

498)this.width=498;' onmousewheel = 'javascript:return big(this)' title="使用PHP、jQuery和CSS制作gravatar头像登录窗" height="300" alt="使用PHP、jQuery和CSS制作gravatar头像登录窗" src="https://lh3.googleusercontent.com/-RFUV0LFAAbo/T7vN5VAW8tI/AAAAAAAAGCU/W8cbVtFpbko/s550/loginbox.png" width="550" />

使用PHP、jQuery和CSS制作gravatar头像登录窗

JavaScript

包含javascript代码。$(".user").keyup(function(){}---user是input标签的名字,我们通过$(this).val()获取input的值。如果email值通过了正则表达式,ajax将会请求avatar.php

<ol class="dp-c">
<li class="alt"><span><span><script><span class="string">"text/javascript"</script></span><span> src=</span><span class="string">"http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"</span><span>>  </span></span></li>
<li>
<span><script><span class="string">"text/javascript"</script></span><span> >  </span>
</li>
<li class="alt">
<span>$(document).ready(</span><span class="keyword">function</span><span>()  </span>
</li>
<li><span>{  </span></li>
<li class="alt">
<span>$(</span><span class="string">"#username"</span><span>).focus();  </span>
</li>
<li>
<span>$(</span><span class="string">".user"</span><span>).keyup(</span><span class="keyword">function</span><span>()  </span>
</li>
<li class="alt"><span>{  </span></li>
<li>
<span class="keyword">var</span><span> email=$(</span><span class="keyword">this</span><span>).val();  </span>
</li>
<li class="alt">
<span class="keyword">var</span><span> dataString = </span><span class="string">'email='</span><span>+ email ;  </span>
</li>
<li>
<span class="keyword">var</span><span> ck_email = /^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i;  </span>
</li>
<li class="alt"><span> </span></li>
<li>
<span class="keyword">if</span><span>(ck_email.test(email))  </span>
</li>
<li class="alt"><span>{  </span></li>
<li><span>$.ajax({  </span></li>
<li class="alt">
<span>type: </span><span class="string">"POST"</span><span>,  </span>
</li>
<li>
<span>url: </span><span class="string">"avatar.php"</span><span>,  </span>
</li>
<li class="alt"><span>data: dataString,  </span></li>
<li>
<span>cache: </span><span class="keyword">false</span><span>,  </span>
</li>
<li class="alt">
<span>success: </span><span class="keyword">function</span><span>(html)  </span>
</li>
<li><span>{  </span></li>
<li class="alt">
<span>$(</span><span class="string">"#img_box"</span><span>).html(</span><span class="string">"<img  alt="PHP、jQ和CSS制作头像登录窗" ><span>+html+</span><span class="string">"?d=mm' />"</span><span>);  </span></span>
</li>
<li><span>}  </span></li>
<li class="alt"><span>});  </span></li>
<li><span>}  </span></li>
<li class="alt"><span> </span></li>
<li><span>});  </span></li>
<li class="alt"><span>});  </span></li>
<li><span> </span></li>
</ol>
Copier après la connexion

498)this.width=498;' onmousewheel = 'javascript:return big(this)' title="使用PHP、jQuery和CSS制作gravatar头像登录窗" height="322" alt="使用PHP、jQuery和CSS制作gravatar头像登录窗" src="https://lh6.googleusercontent.com/-S5T-tywC_QU/T7vffdMlKHI/AAAAAAAAGCk/Fz445g_QAdY/s368/wire.png" width="368" />

使用PHP、jQuery和CSS制作gravatar头像登录窗

HTML 代码

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"login_container"</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"login_box"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"img_box"</span><span class="tag">></span><span class="tag"><span class="tag-name">img</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"http://www.gravatar.com/avatar/?d=mm"</span><span> </span><span class="attribute">alt</span><span>=</span><span class="attribute-value">""</span><span> </span><span class="tag">/></span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span class="tag-name">form</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"login.php"</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"username"</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"input user"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="tag">/></span><span> </span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"password"</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"input passcode"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"password"</span><span> </span><span class="tag">/></span><span> </span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"btn"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"submit"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">" Login "</span><span> </span><span class="tag">/></span><span class="tag"></span><span class="tag-name">form</span><span class="tag">></span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></span></span></span></li>
<li class="alt">
<span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span> </span>
</li>
</ol>
Copier après la connexion

avatar.php

这里包含了十分简单的代码:接收POST过来的email,进行md5加密,返回加密后数据即可。

<ol class="dp-c">
<li class="alt"><span><span><?php  </span></span></span></li>
<li>
<span class="keyword">if</span><span>(</span><span class="vars">$_POST</span><span>[</span><span class="string">'email'</span><span>])  </span>
</li>
<li class="alt"><span>{  </span></li>
<li>
<span class="vars">$email</span><span>=</span><span class="vars">$_POST</span><span>[</span><span class="string">'email'</span><span>];  </span>
</li>
<li class="alt">
<span class="vars">$lowercase</span><span> = </span><span class="func">strtolower</span><span>(</span><span class="vars">$email</span><span>);  </span>
</li>
<li>
<span class="vars">$image</span><span> = md5(</span><span class="vars">$lowercase</span><span>);  </span>
</li>
<li class="alt">
<span class="func">echo</span><span> </span><span class="vars">$image</span><span>;  </span>
</li>
<li><span>}  </span></li>
<li class="alt"><span>?> </span></li>
</ol>
Copier après la connexion

CSS

<ol class="dp-css">
<li class="alt"><span><span class="value">#login</span><span>_container  </span></span></li>
<li><span>{  </span></li>
<li class="alt">
<span class="keyword">background</span><span>:</span><span class="value">url</span><span>(</span><span class="value">blue</span><span>.jpg) </span><span class="value">#006699</span><span>;  </span>
</li>
<li>
<span class="keyword">overflow</span><span>: </span><span class="value">auto</span><span>;  </span>
</li>
<li class="alt">
<span class="keyword">width</span><span>: </span><span class="value">300px</span><span>;  </span>
</li>
<li><span>}  </span></li>
<li class="alt">
<span class="value">#login</span><span>_box  </span>
</li>
<li><span>{  </span></li>
<li class="alt">
<span class="keyword">padding</span><span>:</span><span class="value">60px</span><span> </span><span class="value">30px</span><span> </span><span class="value">30px</span><span> </span><span class="value">30px</span><span>;  </span>
</li>
<li>
<span class="keyword">border</span><span>:</span><span class="value">solid</span><span> </span><span class="value">1px</span><span> </span><span class="value">#dedede</span><span>;  </span>
</li>
<li class="alt">
<span class="keyword">width</span><span>:</span><span class="value">238px</span><span>;  </span>
</li>
<li>
<span class="keyword">background-color</span><span>:</span><span class="value">#fcfcfc</span><span>;  </span>
</li>
<li class="alt">
<span class="keyword">margin-top</span><span>:</span><span class="value">70px</span><span>;  </span>
</li>
<li><span>}  </span></li>
<li class="alt">
<span class="value">#img</span><span>_box  </span>
</li>
<li><span>{  </span></li>
<li class="alt">
<span class="keyword">background-color</span><span>: </span><span class="value">#FFFFFF</span><span>;  </span>
</li>
<li>
<span class="keyword">border</span><span>: </span><span class="value">1px</span><span> </span><span class="value">solid</span><span> </span><span class="value">#DEDEDE</span><span>;  </span>
</li>
<li class="alt">
<span class="keyword">margin-left</span><span>: </span><span class="value">77px</span><span>;  </span>
</li>
<li>
<span class="keyword">margin-top</span><span>: </span><span class="value">-108px</span><span>;  </span>
</li>
<li class="alt">
<span class="keyword">position</span><span>: </span><span class="value">absolute</span><span>;  </span>
</li>
<li>
<span class="keyword">width</span><span>: </span><span class="value">86px</span><span>;  </span>
</li>
<li class="alt">
<span class="keyword">height</span><span>: </span><span class="value">86px</span><span>;  </span>
</li>
<li><span>} </span></li>
</ol>
Copier après la connexion


Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal