Gravatar アバターを含むシンプルで興味深いログイン ボックス機能を設計しました。アバターは電子メール ID に基づいて Gravatar.com からエクスポートされます。この記事は、CSS の非常に基本的な実装と、数行の Jquery および PHP コードです。このログイン ボックスのデザインがあなたの Web プロジェクトに特別な風味を与えることを願っています。この例を試す前に、Gravatar にアバターをアップロードしてください
JavaScript
には JavaScript コードが含まれています。 $(".user").keyup(function(){}---user は入力タグの名前です。$(this).val() を通じて入力値を取得します。電子メールの値が正規表現を渡す場合、ajax avatar.php がリクエストされます
<ol class="dp-c"> <li class="alt"><span><span><script type=</span><span class="string">"text/javascript"</span><span> src=</span><span class="string">"http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"</span><span>></script> </span></span></li> <li><span><script type=</span><span class="string">"text/javascript"</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 src='http://www.gravatar.com/avatar.php?gravatar_id="</span><span>+html+</span><span class="string">"?d=mm' />"</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></script> </span></li> </ol>
PHP、jQuery、CSS を使用して Gravatar アバター ログイン ウィンドウを作成します
HTML コード
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><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></li> <li> <span class="tag"><</span><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> </li> <li class="alt"> <span class="tag"><</span><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><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> </li> <li> <span class="tag"><</span><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><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><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><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> </li> <li class="alt"> <span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span> </li> </ol>
avatar.php
これには非常に単純なコードが含まれています。電子メールを POST して md5 暗号化を実行し、暗号化されたデータを返します。
りーCSS
りー