SNAP的另类实现,采用js生成IFRAME内嵌框架的形式实现链接的网页'图像预览'

SNAP的另类实现,采用iFRAME,内嵌框架的形式.纯粹娱乐.
通过调整iframe对象style 的zoom 属性,将页缩小.有点象抓的缩略图;并且不需要后台程序的支持,完全前端javascript完成,不过还是有很多的问题的,如果目标地址写了防止在别人框架内的脚本代码或者目标页的脚本运行出错,都会有影响.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script defer="defer" type="text/javascript" charset="gb2312"> /** 原作者:未知 该代码功能很简单,将它做了很小部分的修改 **/ <!-- var tPopWait = 100; //停留tWait豪秒后显示提示。 var tPopShow = 60000; //显示tShow豪秒后关闭提示 var showPopStep = 30; //半透明步长 var popOpacity = 90; //透明度 var fontcolor = "#000000"; //文字颜色 var bgcolor = "white"; //背景颜色 var bordercolor = "black"; //边框颜色 var sPop=null; var curShow=null; var tFadeOut=null; var tFadeIn=null; var tFadeWaiting=null; var snapPanel = ""; snapPanel += "<style type='text/css'id='defaultPopStyle'>"; snapPanel += ".cPopText { background-color: "+bgcolor+";color:"+fontcolor+"; border: 1px "+bordercolor+" solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 240px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}"; snapPanel += "</style>"; snapPanel += "<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>"; document.body.innerHTML += snapPanel; function showPopupText() { try{ var o= event.srcElement; if(o.id == "dypopLayer") return; MouseX = event.x; MouseY = event.y; if(o.tagName=="A" && o.href!=undefined && o.href!=null && o.href!="") { //获取link 的 href 属性,并清除掉 alt && title 属性,以免显示两个提示. o.dypop=o.href; if(o.alt!=null&&o.alt!="") { o.alt="" } if(o.title!=null&&o.title!="") { o.title="" } document.title = o.href; } if(o.dypop!=sPop) { sPop = o.dypop; clearTimeout(curShow); clearTimeout(tFadeOut); clearTimeout(tFadeIn); clearTimeout(tFadeWaiting); if(sPop==null||sPop=="") { dypopLayer.innerHTML=""; dypopLayer.style.filter="Alpha()"; dypopLayer.filters.Alpha.opacity=0; } else { if(o.dyclass!=null)popStyle=o.dyclass else popStyle="cPopText"; curShow=setTimeout("showIt()",tPopWait); } } } catch(e) { alert(e); } } //避免重复引发onload function changeImage(img,url){ if(img.src==sServiceUrlRoot+"/Caches/loading.gif"){ img.src = url; } } function showIt() { dypopLayer.className=popStyle; //加入img标签 var key=Math.floor( Math.random() * 2000000); var imageHtml = "<iframe width='100%' height='100%' border='1' src='" + sPop + "' style='zoom:0.5;'></iframe>"; dypopLayer.style.width = 320; dypopLayer.style.height = 240; popWidth=dypopLayer.clientWidth; popHeight=dypopLayer.clientHeight; dypopLayer.innerHTML= imageHtml; if(MouseX+12+popWidth>document.body.clientWidth)popLeftAdjust=-popWidth-24 else popLeftAdjust=0; if(MouseY+12+popHeight>document.body.clientHeight)popTopAdjust=-popHeight-24 else popTopAdjust=0; dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust; dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust; dypopLayer.style.filter="Alpha(Opacity=0)"; fadeOut(); } function fadeOut() { if(dypopLayer.filters.Alpha.opacity<popOpacity) { dypopLayer.filters.Alpha.opacity+=showPopStep; tFadeOut=setTimeout("fadeOut()",1); } else { dypopLayer.filters.Alpha.opacity=popOpacity; tFadeWaiting=setTimeout("fadeIn()",tPopShow); } } function fadeIn() { if(dypopLayer.filters.Alpha.opacity>0) { dypopLayer.filters.Alpha.opacity-=1; tFadeIn=setTimeout("fadeIn()",1); } } document.οnmοuseοver=showPopupText; --> </script> </head> <body style="height: 700px;"> | <a href="http://www.cnblogs.com/" target="_blank">http://www.cnblogs.com</a> | <a href="http://chinasf.cnblogs.com/" target="_blank">http://chinasf.cnblogs.com</a> | <a href="http://www.sina.com/" target="_blank">http://www.sina.com</a> | <a href="http://www.csdn.net/" target="_blank">http://www.csdn.net</a> | <a dypop="http://baidu.com/" href="http://baidu.com/" target="_blank">http://baidu.com</a> | <a dypop="http://www.google.com/" href="http://www.google.com/" target="_blank">http://www.google.com</a> | <a dypop="http://community.csdn.net/" href="http://community.csdn.net/" target="_blank">http://community.csdn.net</a> | <a dypop="http://www.gameres.com/" href="http://www.gameres.com/" target="_blank"> http://www.gameres.com</a> | <a href="about:blank" target="_blank">about:blank</a> | </body> </html>
   提示:您可以先修改部分代码再运行

转载于:https://www.cnblogs.com/Chinasf/archive/2006/12/29/607386.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您想问如何使用nestjs和node-snap7实现读写bool数组和单个bool值。首先,您需要安装node-snap7模块,可以通过以下命令进行安装: ``` npm install node-snap7 ``` 接下来,您可以使用以下代码来读取一个bool值: ```typescript import { Injectable } from '@nestjs/common'; import snap7 from 'node-snap7'; @Injectable() export class Snap7Service { private client: snap7.S7Client; constructor() { this.client = new snap7.S7Client(); } async readBool(db: number, start: number): Promise<boolean> { await this.client.connect('192.168.0.1', 0, 1); const buffer = Buffer.alloc(1); const result = await this.client.readArea(snap7.S7AreaDB, db, start, 1, buffer); await this.client.disconnect(); if (result === 0) { return buffer[0] === 1; } else { throw new Error(`Read bool error: ${result}`); } } } ``` 在上面的代码中,我们首先创建了一个Snap7Service类来封装node-snap7模块。在该类的构造函数中,我们创建了一个S7Client实例,并在readBool方法中使用它来连接到PLC,并读取位于指定DB和偏移量的bool值。最后,我们通过检查返回的缓冲区中的第一个字节来确定bool值的状态,并关闭连接。 如果您想要读取bool数组,可以使用以下代码: ```typescript import { Injectable } from '@nestjs/common'; import snap7 from 'node-snap7'; @Injectable() export class Snap7Service { private client: snap7.S7Client; constructor() { this.client = new snap7.S7Client(); } async readBoolArray(db: number, start: number, length: number): Promise<boolean[]> { await this.client.connect('192.168.0.1', 0, 1); const buffer = Buffer.alloc(length); const result = await this.client.readArea(snap7.S7AreaDB, db, start, length, buffer); await this.client.disconnect(); if (result === 0) { const boolArray = []; for (let i = 0; i < length; i++) { boolArray.push(buffer[i] === 1); } return boolArray; } else { throw new Error(`Read bool array error: ${result}`); } } } ``` 在上面的代码中,我们使用类似的方法来连接到PLC并读取bool数组。我们首先创建一个长度为指定长度的缓冲区,并使用client.readArea方法来读取bool数组。最后,我们通过遍历缓冲区中的每个字节并将其转换为布尔型来构建bool数组。 如果您想要写入bool值或bool数组,可以使用以下代码: ```typescript import { Injectable } from '@nestjs/common'; import snap7 from 'node-snap7'; @Injectable() export class Snap7Service { private client: snap7.S7Client; constructor() { this.client = new snap7.S7Client(); } async writeBool(db: number, start: number, value: boolean): Promise<void> { await this.client.connect('192.168.0.1', 0, 1); const buffer = Buffer.alloc(1); buffer.writeUInt8(value ? 1 : 0, 0); const result = await this.client.writeArea(snap7.S7AreaDB, db, start, 1, buffer); await this.client.disconnect(); if (result !== 0) { throw new Error(`Write bool error: ${result}`); } } async writeBoolArray(db: number, start: number, values: boolean[]): Promise<void> { await this.client.connect('192.168.0.1', 0, 1); const buffer = Buffer.alloc(values.length); for (let i = 0; i < values.length; i++) { buffer.writeUInt8(values[i] ? 1 : 0, i); } const result = await this.client.writeArea(snap7.S7AreaDB, db, start, values.length, buffer); await this.client.disconnect(); if (result !== 0) { throw new Error(`Write bool array error: ${result}`); } } } ``` 在上面的代码中,我们使用writeArea方法来写入指定的bool值或bool数组。我们首先将布尔值或布尔数组转换为一个缓冲区,然后使用writeArea方法将其写入到PLC的指定DB和偏移量中。最后,我们检查返回结果以确保写入操作成功。 希望这些代码可以帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值