MSN弹出式窗口popup的JS实现

本文参考 【玉开】的blog。
效果图:

实现这样的效果步骤如下:
1.把下面的代码添加到博客园管理-选项-Configure-页首Html代码
None.gif < script language = " javascript " >
None.gif
var  divTop,divLeft,divWidth,divHeight,docHeight,docWidth,i  =   0 ;
None.gif
var  eMsg  =   new  Object();
None.gifeMsg.id 
=  'eMsg';
ExpandedBlockStart.gifContractedBlock.gifeMsg.obj 
=   function () dot.gif {return document.getElementById(eMsg.id);} ;
None.gif
ExpandedBlockStart.gifContractedBlock.gifeMsg.onLoad 
=   function () dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
trydot.gif{
InBlock.gif        divTop 
= parseInt(eMsg.obj().style.top,10); 
InBlock.gif        divLeft 
= parseInt(eMsg.obj().style.left,10);
InBlock.gif        divHeight 
= parseInt(eMsg.obj().offsetHeight,10);
InBlock.gif        divWidth 
= parseInt(eMsg.obj().offsetWidth,10);
InBlock.gif        docWidth 
= document.body.clientWidth;
InBlock.gif        docHeight 
= document.body.clientHeight;//内容高度
InBlock.gif
        //alert(document.body.scrollTop);
InBlock.gif
        //return;
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*
InBlock.gif        alert("top.window.screen.availHeight "+docHeight);
InBlock.gif        alert("top.window.screenTop "+top.window.screenTop);        
InBlock.gif        alert("document.body.clientHeight "+document.body.clientHeight);        
InBlock.gif        alert("document.body.clientWidth "+docWidth);        
InBlock.gif        alert("document.documentElement.scrollTop "+document.documentElement.scrollTop);        
ExpandedSubBlockEnd.gif
*/

InBlock.gif        eMsg.obj().style.top 
= parseInt(document.body.scrollTop,10+ docHeight + 10;//parseInt(document.body.scrollTop,10)被document.documentElement.scrollTop替换
InBlock.gif
        eMsg.obj().style.left = parseInt(document.body.scrollLeft,10+ docWidth - divWidth;
InBlock.gif        eMsg.obj().style.visibility
="visible";
InBlock.gif        eMsg.timer 
= window.setInterval(eMsg.move,2);
InBlock.gif       
InBlock.gif        
//hp.skin.onBeforChange = function(){
InBlock.gif
        //    if(eMsg.obj())eMsg.obj().parentNode.removeChild(eMsg.obj());
InBlock.gif
        //};
ExpandedSubBlockEnd.gif
    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.onResize 
=   function () dot.gif {
InBlock.gif    i
+=1;
InBlock.gif    
//alert(i);
InBlock.gif
    if(i>1000) eMsg.close();
ExpandedSubBlockStart.gifContractedSubBlock.gif    
trydot.gif{
InBlock.gif        divHeight 
= parseInt(eMsg.obj().offsetHeight,10);
InBlock.gif        divWidth 
= parseInt(eMsg.obj().offsetWidth,10);
InBlock.gif        docWidth 
= document.body.clientWidth;
InBlock.gif        docHeight 
= document.body.clientHeight;
InBlock.gif        eMsg.obj().style.top 
= docHeight - divHeight + parseInt(document.body.scrollTop,10);//parseInt(document.body.scrollTop,10)被document.documentElement.scrollTop替换
InBlock.gif
        eMsg.obj().style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.move 
=   function () dot.gif {
InBlock.gif    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if(parseInt(eMsg.obj().style.top,10<= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))//parseInt(document.body.scrollTop,10)被document.documentElement.scrollTop替换
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif{
InBlock.gif            window.clearInterval(eMsg.timer);
InBlock.gif            eMsg.timer 
= window.setInterval(eMsg.onResize,1);
ExpandedSubBlockEnd.gif        }

InBlock.gif        divTop 
= parseInt(eMsg.obj().style.top,10);
InBlock.gif        eMsg.obj().style.top 
= divTop - 1;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.close 
=   function () dot.gif {
InBlock.gif
//alert('will close');
InBlock.gif
    if(eMsg.obj()) eMsg.obj().parentNode.removeChild(eMsg.obj());
InBlock.gif    
if(eMsg.timer) window.clearInterval(eMsg.timer);
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.createInstance 
=   function (bodyHtml) dot.gif {
InBlock.gif    
//if(!titleHtml || !bodyHtml)throw '必须为titleHtml指定值,必须为bodyHtml指定值。';
InBlock.gif
  try
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
if(eMsg.obj())eMsg.obj().parentNode.removeChild(eMsg.obj());
InBlock.gif    
if(eMsg.timer) window.clearInterval(eMsg.timer);   
InBlock.gif    i
=0;
InBlock.gif    
var odiv = document.createElement('DIV');
InBlock.gif    odiv.id 
= eMsg.id;
InBlock.gif    odiv.innerHTML 
= '<div class="eMsgInner">'
InBlock.gif    
+ '<div class="body" oncontextmenu="eMsg.close();return false;" title="右键关闭">'
InBlock.gif        
+ '<div class="content">'
InBlock.gif        
+ bodyHtml    
InBlock.gif        
+ '</div>'
InBlock.gif    
+ '</div>'
InBlock.gif    
+ '</div>';
InBlock.gif    document.body.appendChild(odiv);
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
None.gif
None.gifwindow.onresize 
=  eMsg.onResize;
None.gif
None.gif
function  eMsgPopup(bodyHtml)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifeMsg.createInstance(bodyHtml);
InBlock.gifeMsg.onLoad();
ExpandedBlockEnd.gif}

None.gif
function  myPopup()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifeMsgPopup('
<div align=left>博主今日推荐:</div>'
InBlock.gif    
+'<br><div align=left><a href="http://live-bj.5d6d.com" target="_blank">北京混混网</a></div>');
ExpandedBlockEnd.gif}

None.gif
None.gif//window.onload
= myPopup();
None.gif
None.gif
</ script >

2.把下面的CSS样式增加到博客园管理-选项-Configure-通过CSS定制页面
ExpandedBlockStart.gif ContractedBlock.gif DIV#eMsg {dot.gif} {
InBlock.gif    background-image
: url(http://www.cnblogs.com/images/cnblogs_com/vagerent/popupBG.gif);
InBlock.gif    visibility
: hidden; 
InBlock.gif    width
: 199px; 
InBlock.gif    height
: 70px; 
InBlock.gif    position
: absolute; 
InBlock.gif    z-index
: 99999; 
InBlock.gif    left
: 0px;
ExpandedBlockEnd.gif
}

None.gifDIV#eMsg DIV.eMsgInner
ExpandedBlockStart.gifContractedBlock.gif
{dot.gif} {
InBlock.gif    background-image
: url(http://www.cnblogs.com/images/cnblogs_com/vagerent/popupBG.gif);
InBlock.gif    height
:70px;
InBlock.gif    width
:199px;
ExpandedBlockEnd.gif
}

None.gif
ExpandedBlockStart.gifContractedBlock.gifDIV.body
{dot.gif} {
InBlock.gif    height
:72px;
InBlock.gif    clear
:both;
InBlock.gif    border-right
: #728eb8 1px solid; 
InBlock.gif    padding-top
: 1px; 
InBlock.gif    border-top
: #728eb8 1px solid;
InBlock.gif    border-left
: #728eb8 1px solid; 
InBlock.gif    color
: #1f336b; 
InBlock.gif    word-break
: break-all;
InBlock.gif    border-bottom
: #b9c9ef 1px solid;
ExpandedBlockEnd.gif
}

ExpandedBlockStart.gifContractedBlock.gifDIV.content
{dot.gif} {text-align:center;font-size: 12px;}
None.gif

3.现在就可以出效果了,不过需要修改那段JS代码,把下面这段修改成自己的文字就可以了。(还有css里面的背景图,最好从我的blog下载然后上传到你自己的blog)
None.gif function  myPopup()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifeMsgPopup('
<div align=left>博主今日推荐:</div>'
InBlock.gif    
+'<br><div align=left><a href="http://live-bj.5d6d.com" target="_blank">北京混混网</a></div>');
ExpandedBlockEnd.gif}
4.具体效果,测试:)  或者点我blog左上角的卡马克的图片试试。


转载于:https://www.cnblogs.com/vagerent/archive/2007/07/02/802975.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 顶象验证码popup是一种防止机器人自动注册的验证码方。在Vue中使用顶象验证码popup可以按照以下步骤进行: 1. 在Vue项目中安装顶象验证码的SDK。可以使用npm或者yarn安装。 2. 在需要使用验证码的组件中引入顶象验证码SDK,通常可以在created或者mounted钩子函数中引入。 3. 在组件中创建一个函数,用于初始化验证码,通常可以命名为initCaptcha。在这个函数中,使用顶象验证码的SDK创建一个验证码实例,同时设置验证成功和验证失败的回调函数。 4. 在组件中使用顶象验证码的SDK创建一个div元素,并将其添加到页面中。这个div元素用于显示验证码的窗口。 5. 在需要验证码窗口的地方,调用之前创建的initCaptcha函数即可。顶象验证码的SDK会自动验证码窗口,用户完成验证后会调用之前设置的回调函数。在回调函数中可以执行需要的操作,例如向后台发送验证结果等。 以上是使用顶象验证码popup在Vue中的基本流程。具体实现可能因项目而异,建议参考官方文档和示例进行操作。 ### 回答2: 在Vue中使用顶象验证码popup,需要按照以下步骤进行操作: 第一步,安装顶象验证码的npm包。在项目根目录下,打开终端,执行以下命令: ``` npm install dxy-captcha --save ``` 第二步,引入顶象验证码组件。在需要使用的组件中,通过`import`语句引入验证码组件: ```javascript import DxyCaptcha from 'dxy-captcha'; ``` 第三步,注册组件。在Vue实例中,使用`components`属性注册组件: ```javascript export default { components: { DxyCaptcha }, // ... } ``` 第四步,在模板中使用组件。在需要使用验证码的地方,使用`<dxy-captcha>`标签声明组件: ```html <template> <div> <!-- ... --> <dxy-captcha appId="your-app-id" onSuccess="handleSuccess" onFailure="handleFailure" ></dxy-captcha> <!-- ... --> </div> </template> ``` 其中,`appId`属性需要替换成你在顶象验证码官网申请到的AppId,`onSuccess`和`onFailure`属性是事件处理函数,在验证码验证成功或失败时会被调用。 第五步,编写事件处理函数。在Vue实例中,编写`handleSuccess`和`handleFailure`函数来处理验证码验证成功和失败的情况: ```javascript export default { // ... methods: { handleSuccess(code) { // 验证码验证成功的处理逻辑 console.log('Verification success, code:', code); }, handleFailure() { // 验证码验证失败的处理逻辑 console.log('Verification failure'); } }, // ... } ``` 至此,就完成了在Vue中使用顶象验证码popup的过程。你可以根据实际需求,进一步调整组件的样和事件处理逻辑。 ### 回答3: 顶象验证码popup在Vue中的用法如下: 1. 首先,在Vue项目中安装顶象验证码的依赖包,并引入顶象验证码的相关文件。 2. 在需要使用顶象验证码的组件中,先在data中定义一个变量用于保存验证结果,例如:verified。 3. 在组件的模板中,添加一个按钮或其他触发窗的元素,并给它绑定一个点击事件。 4. 在点击事件的处理函数中,使用顶象验证码的API验证码窗,并传入一个回调函数。 5. 在回调函数中,判断验证码的验证结果,并将结果保存到verified变量中。 6. 根据verified的值,在模板中展示不同的内容或触发相应的逻辑处理。 下面是一个示例代码: ```javascript <template> <button @click="showPopup">验证码</button> <div v-if="verified">验证通过</div> <div v-else>请先完成验证码验证</div> </template> <script> import { Popup } from '顶象验证码库的路径' export default { data() { return { verified: false } }, methods: { showPopup() { Popup(function (token) { if (token) { // 验证通过 this.verified = true } else { // 验证不通过 this.verified = false } }) } } } </script> ``` 通过以上步骤,在Vue项目中使用顶象验证码popup即可实现对验证码的窗验证,根据验证结果来展示不同的内容或触发相应的逻辑处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值