惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
The GitHub Blog
The GitHub Blog
美团技术团队
Security Latest
Security Latest
The Cloudflare Blog
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security Affairs
腾讯CDC
H
Hacker News: Front Page
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 三生石上(FineUI控件)
C
Check Point Blog
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Security Archives - TechRepublic
Security Archives - TechRepublic
I
InfoQ
量子位
Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
TaoSecurity Blog
TaoSecurity Blog
月光博客
月光博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
D
Docker
Hugging Face - Blog
Hugging Face - Blog
I
Intezer
雷峰网
雷峰网
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
SecWiki News
SecWiki News
N
News and Events Feed by Topic

博客园 - JIN Weijie

基于Entity Framework的自定义分页,增删改的通用实现 基于Dapper的分页实现,支持筛选,排序,结果集总数,多表查询,非存储过程 让Windows 7变成WIFI热点 新浪微博RSS生成器Ver 1.0 同步Twitter帐号 ASTreeView 1.5.8发布(ASP.Net树控件) ASTreeView 1.5.3发布(ASP.NET树控件) ASTreeView 1.4.0发布(ASP.NET树控件) ASTreeView 1.3.0发布(ASP.NET树控件) ASTreeView 1.1.1发布(ASP.NET树控件) 在GoDaddy上部署SubText ASTreeView 1.0发布(一个ASP.NET树控件) 自定义增加Windows xp IIS的连接数 javascript closure(闭包)的一个示例 vmware增加磁盘空间方法以及出错解决 <=本博客已经转移至jinweijie.com=> [js][asp.net]客户端控制validator [asp.net]优化ViewState [js]remove whitespace for firefox [windows]自动拨号脚本
修改Thickbox,预加载图片和点击图片前后浏览
JIN Weijie · 2011-01-01 · via 博客园 - JIN Weijie

2011了,大家新年好!

外面寒冷,躲在家里写写博客还是挺好的。

今天为我的博客修改了下jQuery的Thickbox,增加了预加载图片功能和点击图片前后浏览的功能。

首先看下效果:

http://www.jinweijie.com/photo/?album=1&gallery=3

效果图(看右侧的箭头)

image

先说说预加载功能

点击图片,当图片加载完毕以后,会自动加载后2张图片,这样,浏览起来会变得很顺畅。

主要代码:

替换thickbox.js中的:

imgPreloader = new Image();
imgPreloader.onload = function(){
imgPreloader.onload = null;

imgPreloader = new Image();
prevImg = new Image();
nextImg = new Image();
imgPreloader.onload = function(){
imgPreloader.onload = null;

var tb_links = jQuery('a[class="thickbox"]');
var i = -1;
tb_links.each(function(n) { if (this.href == imgPreloader.src) { i = n; } });


if (i != -1) {
    if (i>0) { prevImg.src = tb_links[i-1].href; }
    if (i+1 < tb_links.length) { 
    
        var imgTemp1 = new Image();
        imgTemp1.src = tb_links[i+1].href; 
        
        if(tb_links[i+2]){
            var imgTemp2 = new Image();
            imgTemp2.src = tb_links[i+2].href; 
        }
        
        if(tb_links[i+3]){
            var imgTemp3 = new Image();
            imgTemp3.src = tb_links[i+3].href; 
        }
    }
}

接着是浏览按钮功能

需要3张图片left.gif, right.gif, pixel.gif。分别是左右和div透明背景图。
然后修改thickbox.css,增加:
#divNavControl{
    position: absolute;
    z-index:999;
}

#divPre{
     height: 100%;
    left: 0;
    position: absolute;
    width: 50%;
    background:url(pixel.gif) repeat;
    cursor:pointer;
}

#divNext{
    height: 100%;
    position: absolute;
    right: 0;
    width: 50%;
    background-color:transparent;
    background:url(pixel.gif) repeat;
    cursor:pointer;
}

#imgLeftArrow{
    position:absolute;
    top:45%;
    left:0;
}

#imgRightArrow{
    position:absolute;
    top:45%;
    right:0;
}

最后修改thickbox.js,由于代码太长了,就不贴出来了,大家有兴趣可以看看,或者直接用就行了。

下载请到 http://www.jinweijie.com/javascript/thickbox-add-previous-and-next-button-on-image-like-lightbox/

这里就不上传了。

谢谢大家,再次祝大家新年快乐!