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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - chenping2008

连接远程数据库,得到数据插入本地表中 php复制目录 PHP删除目录 php统计目录大小 js秒数转换天时分秒 JS切换图片 js 游览器log的记录 2个iframe中checkbox联动 JS Clone函数 JS普通递归的改进 JS随机数的产生方法 JS相等运算符(==)和等同运算符(===) silverlight树形结构区服选择 Mongodb的一些基本概念 Mongodb在Ubuntu下的安装 redis windows下使用及redis命令 Node.js 系列翻译---console Node.js 系列翻译---概要 补充Silverlight中图片显示
相册功能
chenping2008 · 2011-12-25 · via 博客园 - chenping2008

相册在web开发中算是比较常用的功能。网上也有很多jQuery的相册的插件。功能也是非常的强大。

这篇博客上是实现的相册的功能是用到了2个jQuery的插件:

1. jquery.jcarousel.min  这个插件是用来滚动缩略图的。具体的详细信息可以参考。

http://sorgalla.com/jcarousel/ 

2. jquery的ui插件,需要利用其中的dialog的功能。 

具体的代码如下:

HTML代码

 1         <ul id="mycarousel" class="jcarousel-skin-tango">
 2                 <li><img src="meinv1.jpg" width="60" height="60" alt="" /></li>
 3                 <li><img src="meinv2.jpg" width="60" height="60" alt="" /></li>
 4                 <li><img src="meinv3.jpg" width="60" height="60" alt="" /></li>
 5                 <li><img src="meinv4.jpg" width="60" height="60" alt="" /></li>
 6                 <li><img src="meinv5.jpg" width="60" height="60" alt="" /></li>
 7         </ul>
 8         <div id="showDiv">        
 9             <div id="efpLeftArea" class="arrLeft" title="上一张" onclick="prevImg()"></div>
10             <div id="efpRightArea" class="arrRight" title="下一张" onclick="nextImg()"></div>        
11             <div>
12                 <img id="showImg" />
13             </div>

14         </div>

JS代码

 1 $(function(){
 2                 $('#mycarousel').jcarousel({
 3                     scroll:1
 4                 });
 5             
 6                 $("#showDiv").dialog({
 7                     title:"图片显示" ,
 8                     position:"center",
 9                     modal:true,
10                     autoOpen:false,
11                     width:800,
12                     height:600,
13                     resizable:false
14                 });
15             
16                 $("#mycarousel img").click(function(){
17                     $(this).addClass("imgmouseover");
18                     $(this).parent().prevAll("li").children("img").removeClass("imgmouseover");
19                     $(this).parent().nextAll("li").children("img").removeClass("imgmouseover");
20                     $("#showDiv").dialog("open");
21                     $("#showImg").attr("src",$(this).attr("src"));
22                     $("#showDiv").scrollTop(0);
23                     $("#efpLeftArea").height($("#showImg").height());
24                     $("#efpRightArea").height($("#showImg").height());
25                 });
26             
27                 
28             });
29             
30             function nextImg()
31             {
32                 var ele=$("img.imgmouseover");
33                 if(ele.attr("src")!=$("#mycarousel img").last().attr("src"))
34                 {
35                     ele.parent().next().children("img").addClass("imgmouseover");
36                     ele.removeClass("imgmouseover");
37                     $("#showImg").attr("src",ele.parent().next().children("img").attr("src"));
38                     $("#showDiv").scrollTop(0);
39                     $("#efpLeftArea").height($("#showImg").height());
40                     $("#efpRightArea").height($("#showImg").height());
41                     $(".jcarousel-next.jcarousel-next-horizontal").click();
42                 }
43             }
44             function prevImg()
45             {
46                 var ele=$("img.imgmouseover");
47                 if(ele.attr("src")!=$("#mycarousel img").first().attr("src"))
48                 {
49                     ele.parent().prev().children("img").addClass("imgmouseover");
50                     ele.removeClass("imgmouseover");
51                     $("#showImg").attr("src",ele.parent().prev().children("img").attr("src"));
52                     $("#showDiv").scrollTop(0);
53                     $("#efpLeftArea").height($("#showImg").height());
54                     $("#efpRightArea").height($("#showImg").height());
55                     $(".jcarousel-prev.jcarousel-prev-horizontal").click();
56                 }

57             }

外部JS和CSS文件的引用

<style>
            .imgmouseover{
                border:1px solid red
            }
            .arrLeft {
                cursor: url(http://www.sinaimg.cn/edu/images/slidenews/arr_left.cur),auto;
            }
            .arrRight {
                cursor: url(http://www.sinaimg.cn/edu/images/slidenews/arr_right.cur),auto;
            }
            #efpLeftArea {
                width: 50%;
                height: 100%;
                position: absolute;
                left: 0;
                top: 0;
                z-index: 9999;
                background: white;
                opacity: 0;
                filter: Alpha(Opacity=0);
            }
            #efpRightArea {
                width: 50%;
                height: 100%;
                position: absolute;
                right: 0;
                top: 0;
                z-index: 9999;
                background: white;
                opacity: 0;
                filter: Alpha(Opacity=0);
            }
        </style>
        <link type="text/css" href="css/smoothness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />    
        <link type="text/css" href="skins/tango/skin.css" rel="stylesheet" />    
        <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
        <script type="text/javascript" src="jquery.jcarousel.min.js"></script>

运行起来html页面,可以看到一排小的缩略图片,点击小图时dialog会open,然后显示大图,点击大图的左右会实现上一张 下一张的功能。小的缩略图和大图之间会实现滚动的同步。