转载

所谓的“图片预加载”就是先加载一张不清晰的图片,然后加载一张高清图片,实现由模糊到清晰的渐变。防止页面空白影响用户体验。具体效果请看在线演示

原理其实很简单,使用两张图片实现:一张小的缩略图,一张大的高清图,将缩略图拉大到高清图的尺寸(这就是模糊的效果),然后加载高清图片,加载完成修改<img>标签的src。

html代码如下:


  
  
  1. <img src="img_s.jpg" style="width: 409px; height: 307px;" />

js代码如下:

 
 
  1. var img = new Image();
  2. $(img).load(function () {
  3. $('img').attr('src', 'img.jpg');
  4. });
  5. img.src = 'img.jpg';

上面是核心代码。至于进度条等代码,可以右键查看在线演示的源代码。

2  * 带滚动条的图片预加载效果
03  * =======================================
04  * @author keenwon
05  * Full source at http://keenwon.com
06  */
07  
08 (function () {
09     var timing = function () {
10         this._timer = null;
11         this._percent = 0;
12         this._isLoading = false;
13         this._isPause = false;
14         this._step = 2;
15     };
16  
17     timing.prototype = {
18         start: function (url, obj) {
19             var self = this;
20             self._percent = 0;
21  
22             self._loadImg(url);
23  
24             self._timer = setInterval(function () {
25                 self._judge(url, obj);
26                 self._scroll();
27             }, 30);
28         },
29         _pause: function () {
30             this._isPause = true;
31             this._step = 0;
32         },
33         _restart: function () {
34             this._isPause = false;
35             this._step = 3;
36         },
37         _scroll: function () {
38             $('.loading-progress').width(this._percent + "%");
39             this._percent += this._step;
40         },
41         _loadImg: function (url) {
42             var self = this;
43             var img = new Image();
44             $(img).load(function () {
45                 setTimeout(function () {//模拟加载
46                     self._isLoading = true;
47                 }, 2000);
48             });
49             img.src = url;
50         },
51         _judge: function (url, obj) {
52             if (this._percent >= 70 && !this._isLoading) {
53                 this._pause();
54             }
55             if (this._percent >= 70 && this._isLoading && this._isPause) {
56                 this._restart();
57             }
58             if (this._percent >= 100) {
59                 obj.attr("src", url);
60                 this.destroy();
61             }
62         },
63         destroy: function () {
64             this._percent = 0;
65             clearInterval(this._timer);
66             $('.loading').hide();
67         }
68     }
69  
70     if (typeof window.timing == 'undefined' || window.timing == null) {
71         window.timing = new timing();
72     }
73 })();
74  
75 $(function () {
76     timing.start('../img/load-image.jpg', $("img").eq(0));
77 });


voicewo 是一个专门用于在网页中实现语音识别转换的jQuery插件。开发人员可以用voicewo将用户的语音转换成文字,插入到指定的HTML表单里,无缝地与Java、.NET、PHP、ASP等多种编程语言集成。适合在聊天室、评论框、论坛、博客、电子邮件等互联网应用中使用。

项目地址1:http://www.yyblog.cn/category/project/voicewo
项目地址2:http://www.oschina.net/p/voicewo
标签: voicewo


[代码][HTML]代码     跳至 [1] [全屏预览]

01 <!DOCTYPE html>
02 <html>
03 <head>
04 <title>Voicewo jQuery Plugin Demo</title>
05 <link rel="stylesheet" type="text/css" href="voicewo.css">
06 <script src="jquery-1.11.0.min.js" type="text/javascript"></script>
07 <script src="jquery.voicewo.js" type="text/javascript"></script>
08 <script type="text/javascript">
09 $(document).ready(function(){
10    $('#btn').voicewo({
11       'width'        : 92,
12       'height'       : 25,
13       'outputId'     : 'txt',
14       'buttonImage'  : 'btn.png',
15       'swf'          : 'voicewo.swf'
16    });
17 })
18 </script>
19 </head>
20 <body>
21    <textarea id="txt" cols="60" name="txt" rows="6"></textarea>
22    <div id="btn"></div>
23 </body>
24 </html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值