Javascript返回页面顶部的滚动特效
作者:admin 日期:2012-04-29
和前面的一篇文章作用一样,这个代码写得不错!
- var goto_top_type = -1;
- var goto_top_itv = 0;
- function goto_top_timer()
- {
- var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
- var moveby = 15;
- y -= Math.ceil(y * moveby / 100);
- if (y < 0) {
- y = 0;
- }
- if (goto_top_type == 1) {
- document.documentElement.scrollTop = y;
- }
- else {
- document.body.scrollTop = y;
- }
- if (y == 0) {
- clearInterval(goto_top_itv);
- goto_top_itv = 0;
- }
- }
- function goto_top()
- {
- if (goto_top_itv == 0) {
- if (document.documentElement && document.documentElement.scrollTop) {
- goto_top_type = 1;
- }
- else if (document.body && document.body.scrollTop) {
- goto_top_type = 2;
- }
- else {
- goto_top_type = 0;
- }
- if (goto_top_type > 0) {
- goto_top_itv = setInterval('goto_top_timer()', 50);
- }
- }
- }
有时间研究下这个网站的效果:http://webdesignerwall.com/
Javascript实现网页平滑滚动回到顶部
作者:admin 日期:2012-04-29
很多网页在下方都会放置一个“返回顶部”按钮,尤其是页面底部没有导航的网页,这样可以帮助访客重新找到导航或者重温一遍广告(想得真美)。随着近几年来 JavaScript 的应用日渐广泛,滑动效果无处不在,于是我也跟跟风,将返回顶部功能做成了滑动效果。后来为了更贴合物理特征, 改造做成了减速的滑动效果。
首先说一下原理吧,我们会获取滚动条到页面顶部的距离,然后上移一定的距离;再获取滚动条到页面顶部的距离,上移一定的距离(比上一次小一点);以此类推 ...
- <script type="text/javascript">
- /**
- * 回到页面顶部
- * @param acceleration 加速度
- * @param time 时间间隔 (毫秒)
- **/
- function goTop(acceleration, time) {
- acceleration = acceleration || 0.1;
- time = time || 16;
- var x1 = 0;
- var y1 = 0;
- var x2 = 0;
- var y2 = 0;
- var x3 = 0;
- var y3 = 0;
- if (document.documentElement) {
- x1 = document.documentElement.scrollLeft || 0;
- y1 = document.documentElement.scrollTop || 0;
- }
- if (document.body) {
- x2 = document.body.scrollLeft || 0;
- y2 = document.body.scrollTop || 0;
- }
- var x3 = window.scrollX || 0;
- var y3 = window.scrollY || 0;
- // 滚动条到页面顶部的水平距离
- var x = Math.max(x1, Math.max(x2, x3));
- // 滚动条到页面顶部的垂直距离
- var y = Math.max(y1, Math.max(y2, y3));
- // 滚动距离 = 目前距离 / 速度, 因为距离原来越小, 速度是大于 1 的数, 所以滚动距离会越来越小
- var speed = 1 + acceleration;
- window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
- // 如果距离不为零, 继续调用迭代本函数
- if(x > 0 || y > 0) {
- var invokeFunction = "goTop(" + acceleration + ", " + time + ")";
- window.setTimeout(invokeFunction, time);
- }
- }
- </script>
调用方法:
- <a href="#" onclick="goTop();return false;">TOP</a>
Javascript实现透明度渐变效果
作者:admin 日期:2012-04-29
vb6 winhttp 用法操作
作者:admin 日期:2012-04-29
Dim WithEvents oreq As WinHttpRequest
Private Sub Command1_Click()
' Create a WinHttpRequest object.
Set oreq = New WinHttpRequest
' Open an HTTP connection.
oreq.Open "GET", "http://ServerName/ASPPage.asp", True
' Set the receive timeout to 3 seconds.
oreq.SetTimeouts 60000, 60000, 60000, 3000
' Send an HTTP request to the server.
oreq.Send
End Sub
Private Sub oreq_OnError(ByVal ErrorNumber As Long, ByVal ErrorDescription As String)
' Display the description of the error.
MsgBox ErrorDescription
End Sub
Private Sub oreq_OnResponseFinished()
' Display the response from the server.
MsgBox oreq.ResponseText
End Sub
ServerXMLHTTP及XMLHTTP的差别
作者:admin 日期:2012-04-29
一般在 client side 的 ajax 会用到这个 component (for IE) Microsoft.XMLHTTP, 若是在 server 端的 asp 程序代码使用这组 code, 来访问其他站台的内容时, 可以利用程序代码如下:
- Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
- xmlhttp.Open "GET", "http://www.baidu.com/", False
- xmlhttp.Send
- Response.Write xmlhttp.ResponseTEXT
- Set xmlhttp = Nothing
不过这个有一些些问题, 因为 XMLHTTP 本身的工作行为是绑在 IE API 上, 当然是有好有坏, 根据微软的文件, 这组组件是适合用在客户端而非 server 端, 在使用上会有一些稳定及效能的问题, 不过更有趣的还有一个地方, 就是他会增进效能而在本机的文件系统上存入访问的内容, 路径如下:
C:\WINDOWS\Temp\Temporary Internet Files\Content.IE5
也就是说, 会占用掉部分的空间, 但实际观察又不全然是这种 cache 的状况, 因为相同的网页, 被重复 reload 时, 该 cache 用的目录居然也会成长, 也就是说, 原来设计为 cache 的功能, 也有可能用不到, 但用不到还没关系, 会一直占用空间成长(无上限), 这个就比较麻烦了.
之前笔者在追踪一个案例(c:碟占用空间持续成长的状况), 原来就是这个组件的毛病, 实际再测, 若是访问的网页是非 xml 时, 似乎就没有这种状况, 不过大多数的应用环境, 数据都会选 xml 的方式来传送, 所以仍会有这个问题存在.
为了解决这个问题, 还有另一组组件可供使用, MSXML2.ServerXMLHTTP, 这组组件提供了更稳定的方式来执行前述功能, 而且几乎完全兼容语法, 并提供了更多的功能, 也不会产生大量的cache 临时文件, 我们来看看微软官网上对此二者的比较:
http://support.microsoft.com/kb/290761
主要差异点如下:
XMLHTTP is designed for client applications and relies on URLMon, which is built upon Microsoft Win32 Internet (WinInet). ServerXMLHTTP is designed for server applications and relies on a new HTTP client stack, WinHTTP. ServerXMLHTTP offers reliability and security and is server-safe. For more information, see the MSXML Software Development Kit (SDK) documentation.
如此一来便可以很清楚地了解在 asp 程序内, 使用 XMLHTTP 及 ServerXMLHTTP 的差异了, 将上面的程序代码改为:
- Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
- xmlhttp.Open "GET", "http://diary.tw/tim/", False
- xmlhttp.Send
- Response.Write xmlhttp.ResponseTEXT
- Set xmlhttp = Nothing
广告位