Home php教程 php手册 网易,佳人有约登录效果

网易,佳人有约登录效果

Jun 13, 2016 am 11:21 AM
and The essential Function Finish us dismantle Effect show Log in of NetEase transparent hide

我们先把上面拆解出来的功能完成!
1。透明层(显示与隐藏)
关键是要同时设置下面这几个样式,才能使主流浏览器上都现实透明的效果。

filter= 'Alpha(Opacity=50)';
MozOpacity ='0.5';
opacity='0.5';


可能很多人都知道,类似这种在透明层上现实东西的效果,多源至于一个称为lightbox的效果。这里我也这样命名:

function Lightbox(id)
{
        this.box = this.createBox();
        this.id  = id||'lightbox_id';
}
Lightbox.prototype=
{
        createBox:function(){
                var box = document.getElementById(this.id)||document.createElement('div');
                box.id = box.id||this.id;
                with(box.style){
                        position='absolute';
                        left='0';
                        top='0';
                        width='100%';
                        height='100%';
                        zIndex='1000';
                        background='#ccc';
                        filter= 'Alpha(Opacity=50)';
                        MozOpacity ='0.5';
                        opacity='0.5';
                        display='none';
                }
                document.body.appendChild(box);
                return box;
        },
        show:function(){
                this.box.style.height= document.documentElement.scrollHeight+'px';
                this.box.style.display = '';
        },
        hide:function(){
                this.box.style.display = 'none';
        }
}


2。表单提交(ajax或iframe)
迅雷上的是用的iframe,我们这里先说iframe
iframe就简单多了,form的target属性设置为某个iframe的name就可以了。设置iframe的onload属性,那么当表单提交完成以后他就会执行相应处理。





如果用ajax的话,代码也很简单。可能大家用的js框架不一样。但绝大多数都大同小异,我相信大家一看就知道是什么意思。
类我就不在这列举了,我只写一下怎么用它。
这其实就是ajax in action这本书上的那个net类。

/*很多人可能会说,为什么没用encodeURIComponent避免乱码?这里不需要使用encodeURIComponent了,在类里面调用过了*/
/**
* 'login.php':登陆验证页[废话]
*  Login.checkLogin:ajax回调函数[废话]
*  loadXMLDoc的参数,表单里要传递的数据[废话]
*/

new Ajax('login.php',Login.checkLogin).loadXMLDoc({
        username:document.getElementById('username').value,
        password:document.getElementById('password').value,
        vcode:document.getElementById('vcode').value
});


3。select的显示与隐藏,以及cookie操作。
既然select不能被div挡住,那就把他干掉吧!

var Select={
        show:function(){
                var selects=document.getElementsByTagName('select');
                for(var m=0;m        },
        hide:function(){
                var selects=document.getElementsByTagName('select');
                for(var m=0;m        }
}


还要准备一套cookie函数
网络最大的好处:对于某些问题,你只需知道该干什么就可以了,至于具体该怎么做已经有人帮你做好了。
下面我就随便在论坛里搜了一下,就找到了一个
http://www.phpchina.com/bbs/view ... a=page=1&sid=4jSn3r

var Cookie=
{
        check:function(){
                 //判断cookie是否开启
                 var cookieEnabled=(navigator.cookieEnabled)? true : false;
                 //如果浏览器不是ie4+或ns6+
                 if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){
                  document.cookie="testcookie";
                  cookieEnabled=(document.cookie=="testcookie")? true : falsedocument.cookie="";
                 }
                
                 //如果没有开启
                 if(cookieEnabled){
                  return true;
                 }else{
                  return false;
                 }
        },
        add:function(name,value,expireHours){
                 var cookieString=name+"="+escape(value);
                 //判断是否设置过期时间
                 if(expireHours>0){
                  var date=new Date();
                  date.setTime(date.getTime+expireHours*3600*1000);
                  cookieString=cookieString+"; expire="+date.toGMTString();
                 }
                 document.cookie=cookieString;
        },
        get:function(name){
                 var strCookie=document.cookie;
                 var arrCookie=strCookie.split("; ");
                 for(var m=0;m                     var arr=arrCookie[m].split("=");
                     if(arr[0]==name){
                           return unescape(arr[1]);
                     }
                 }
                 return false;
        },
        del:function(name){
                 var date=new Date();
                 date.setTime(date.getTime()-10000);
                 document.cookie=name+"=; expire="+date.toGMTString();
        }

}


4。前面提到的回调函数以及后台的两个页面
最后再说一下前面提到的回调函数Login.checkLogin。登陆后你需要做什么,写在Login.loginSuccess里就行了,最后为了方便使用稍有改变。

/*这里没有检验是否支持cookie,在login弹出的时候检测了.不支持cookie的话,登陆窗口都弹不出来。*/
var Login=
{
        statu: 0,
         /*这就是里登陆成功的话,需要做的处理。通常是把整个页面登陆前后不同的地方处理一下。你可以重载一下*/
        loginSuccess:function(){
                document.getElementById('login_result').innerHTML=Cookie.get('username')+'已经登陆';
                alert('登陆成功了!');
        },
         /*这就是里登陆失败的话,需要做的处理。通常是把整个页面登陆前后不同的地方处理一下。你可以重载一下*/
        loginOutSuccess:function(){
                document.getElementById('login_result').innerHTML=Cookie.get('username')+'刚成功退出';
                alert('退出成功!');
        },
        checkLogin:function(){
                if(Login.statu==1&&Cookie.get('loginStatu')==1){
                        new LoginDialog('login_box').hide();
                        Login.loginSuccess();
                }else if(Login.statu==2&&Cookie.get('loginStatu')==0){
                        Login.statu=0;
                        Login.loginOutSuccess();
                }else if(Login.statu==1){
                        alert('请检查你的用户名,密码以及验证码!');
                }
        },
        getVcode:function(){
        document.getElementById('verify_code').src='vcode.php?cachetime='+new Date().getTime();
        },
        loginOut:function(){
                Login.statu=2;
                document.getElementById('login_submit_iframe').contentWindow.location='loginout.php';
        }
}


后台的代码我就不细说了,各自系统有各自的区别。我这里把测试用的代码贴出来,并说一下这些文件该做什么,你只要保证的你页面有这些作用就行了。


/**
* header里设置的字符编码格式要和你前台的一致,否则当出现双字节字符的时候就会出现乱码.
* 其他的都可以用setCookie的方式,写在cookie里传到前台。
* 其中标志登陆成功的 'loginStatu'必须设为1,其他的就看你的登陆是怎么处理的了
*/
header('content-type:text/html; charset=utf-8');
session_start();
$username = 'phpchina';
$password = 'phpchina';
if($username==$_POST['username']&&$password==$_POST['password']&&$_SESSION['vcode']==$_POST['vcode']){
        setcookie('username','phpchina');
        setcookie('loginStatu','1');
}?>

 

/*验证码程序就不用说了吧!我这里是测试用的,所以就随便截了个时间做验证码*/
session_start();
$_SESSION['vcode'] = substr(time(),-4);
$im = imagecreatetruecolor(40, 20);
$bg = imagecolorallocate($im, 225, 225, 225);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagefill($im,1,1,$bg);
imagestring($im, 5, 0, 0, $_SESSION['vcode'], $textcolor);
header("Content-type:image/jpeg");
imagejpeg($im);
?>

最后看看LoginDialog类理解全过程:

function LoginDialog(formid)
{
    this.dialog = document.getElementById(formid||'login_box');
    this.overDiv = this.overDiv ||new Lightbox();
}
LoginDialog.prototype =
{
    show:function(){
        if(!Cookie.check()){alert('你的浏览器不支持cookie,无法正常登陆');return}
        else if(Cookie.get('loginStatu')==1){alert('你已经登陆!');return}
        Login.statu=1;
        this.overDiv.show();
        Select.hide();
        Login.getVcode();
        this.dialog.style.display='';
    },
    hide:function(){
        Login.statu=0;
        this.overDiv.hide();
        Select.show()
        this.dialog.style.display='none';
    }
}


主要是看show()
hide()只是还原操作

//当不支持cookie的时候提示错误,并退出
if(!Cookie.check()){alert('你的浏览器不支持cookie,无法正常登陆');return}

//当支持cookie而cookie.loginstatu的值为1时,说明已经登陆。就不用重复登陆了。
else if(Cookie.get('loginStatu')==1){alert('你已经登陆!');return}

//设置Login.statu=1;表示当前正在做登陆操作
Login.statu=1;

//透明背景层显示
this.overDiv.show();

//隐藏select
Select.hide();

//刷新验证码
Login.getVcode();

//显示登陆窗口
this.dialog.style.display='';
在完成以上这些步骤以后,就是分为iframe还是ajax两种方式提交表单了。
而提交完表单后:
如果是iframe形式提交,iframe的onload事件会调用Login.checkLogin(),当check成功时,他会对应调用Login.loginSuccess()和Login.loginOutSuccess()
而ajax则是把Login.checkLogin做为回调函数来激活。
因此,登陆成功后具体做什么由 Login.loginSuccess()和Login.loginOutSuccess()决定。使用的时候,重载一下它们就可以了。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
Users encounter rare glitches: Samsung Watch smartwatches suddenly experience white screen issues Users encounter rare glitches: Samsung Watch smartwatches suddenly experience white screen issues Apr 03, 2024 am 08:13 AM

You may have encountered the problem of green lines appearing on the screen of your smartphone. Even if you have never seen it, you must have seen related pictures on the Internet. So, have you ever encountered a situation where the smart watch screen turns white? On April 2, CNMO learned from foreign media that a Reddit user shared a picture on the social platform, showing the screen of the Samsung Watch series smart watches turning white. The user wrote: "I was charging when I left, and when I came back, it was like this. I tried to restart, but the screen was still like this during the restart process." Samsung Watch smart watch screen turned white. The Reddit user did not specify the smart watch. Specific model. However, judging from the picture, it should be Samsung Watch5. Previously, another Reddit user also reported

Kyushu Fengshen Assassin 4S Radiator Review Air-cooled 'Assassin Master' Style Kyushu Fengshen Assassin 4S Radiator Review Air-cooled 'Assassin Master' Style Mar 28, 2024 am 11:11 AM

Speaking of ASSASSIN, I believe players will definitely think of the master assassins in "Assassin's Creed". They are not only skilled, but also have the creed of "devoting themselves to the darkness and serving the light". The ASSASSIN series of flagship air-cooled radiators from the appliance brand DeepCool coincide with each other. Recently, the latest product of this series, ASSASSIN4S, has been launched. "Assassin in Suit, Advanced" brings a new air-cooling experience to advanced players. The appearance is full of details. The Assassin 4S radiator adopts a double tower structure + a single fan built-in design. The outside is covered with a cube-shaped fairing, which has a strong overall sense. It is available in white and black colors to meet different colors. Tie

NetEase announced the suspension of 'Marvel Super War', which was Marvel's first MOBA game! NetEase announced the suspension of 'Marvel Super War', which was Marvel's first MOBA game! Apr 18, 2024 am 10:50 AM

NetEase's "Marvel Super War" announced that it will terminate operations and close the game server at 15:00 on June 17, 2024. The download entrance for all platforms has now been closed, and game recharge and new user registration have been stopped. As Marvel's first MOBA mobile game, this game authentically displays the combat characteristics of superheroes and restores the grand world view of the Marvel universe. In the game, you will be able to assemble in the parallel universe with the Avengers, X-Men, Fantastic Four and many superheroes and super villains, and compete with Iron Man, Captain America, Spider-Man, Loki, Thanos, Deadpool Wait for more than 60 classic Marvel characters to fight together!

Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers. Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers. Apr 23, 2024 am 08:04 AM

A large model that can automatically analyze the content of PDFs, web pages, posters, and Excel charts is not too convenient for workers. The InternLM-XComposer2-4KHD (abbreviated as IXC2-4KHD) model proposed by Shanghai AILab, the Chinese University of Hong Kong and other research institutions makes this a reality. Compared with other multi-modal large models that have a resolution limit of no more than 1500x1500, this work increases the maximum input image of multi-modal large models to more than 4K (3840x1600) resolution, and supports any aspect ratio and 336 pixels to 4K Dynamic resolution changes. Three days after its release, the model topped the HuggingFace visual question answering model popularity list. Easy to handle

Huntkey MX750P full module power supply review: 750W of concentrated platinum strength Huntkey MX750P full module power supply review: 750W of concentrated platinum strength Mar 28, 2024 pm 03:20 PM

With its compact size, the ITX platform has attracted many players who pursue the ultimate and unique beauty. With the improvement of manufacturing processes and technological advancements, both Intel's 14th generation Core and RTX40 series graphics cards can exert their strength on the ITX platform, and gamers also There are higher requirements for SFX power supply. Game enthusiast Huntkey has launched a new MX series power supply. In the ITX platform that meets high-performance requirements, the MX750P full-module power supply has a rated power of up to 750W and has passed 80PLUS platinum level certification. Below we bring the evaluation of this power supply. Huntkey MX750P full-module power supply adopts a simple and fashionable design concept. There are two black and white models for players to choose from. Both use matte surface treatment and have a good texture with silver gray and red fonts.

NetEase NetEase Mar 28, 2024 pm 12:50 PM

On March 27, 2024, Beijing time, NetEase Games and Marvel Games officially announced a new game: the superhero PVP team shooting game "Marvel Rivals". Players can choose their favorite characters from a rich and diverse lineup of superheroes and super villains to form an all-star team, and use their unique superpowers to engage in exciting battles on various breakable maps in the Marvel multiverse. "We are very excited to bring "Marvel Confrontation" to players around the world. We have always loved the Marvel Universe and its characters, and we are excited to develop this game." The main creative team of "Marvel Contest" said, "This is exactly the game we dreamed of creating, and we are extremely proud to be able to turn it from a dream into a reality." "NetEase

Exquisite light and shadow art in spring, Haqu H2 is the cost-effective choice Exquisite light and shadow art in spring, Haqu H2 is the cost-effective choice Apr 17, 2024 pm 05:07 PM

With the arrival of spring, everything revives and everything is full of vitality and vitality. In this beautiful season, how to add a touch of color to your home life? Haqu H2 projector, with its exquisite design and super cost-effectiveness, has become an indispensable beauty in this spring. This H2 projector is compact yet stylish. Whether placed on the TV cabinet in the living room or next to the bedside table in the bedroom, it can become a beautiful landscape. Its body is made of milky white matte texture. This design not only makes the projector look more advanced, but also increases the comfort of the touch. The beige leather-like material adds a touch of warmth and elegance to the overall appearance. This combination of colors and materials not only conforms to the aesthetic trend of modern homes, but also can be integrated into

How to deeply clean the hidden junk on your phone (completely remove junk from your phone's memory) How to deeply clean the hidden junk on your phone (completely remove junk from your phone's memory) Jun 01, 2024 am 09:29 AM

Mobile phones have become an indispensable part of our daily lives, with the continuous advancement of technology and the popularity of smartphones. These junk files take up valuable storage space, and over time, a large amount of hidden junk will accumulate in the phone and cause the performance of the phone to degrade, however. Knowing how to deeply clean hidden junk on your phone has become essential knowledge for every mobile phone user. 1. Find and clear useless application caches 2. Delete applications that are no longer used 3. Clean photo and video cache 4. Thoroughly clean temporary files and download folders 5. Organize and clean contact and text message records 6. Clean system cache 7. Uninstall useless system applications 8. Clean browser cache and history 9. Delete invalid music and audio files 10. Optimize mobile phone file system

See all articles