图片展示js特效
html 代码片段,做一个table表格
<table width="798" height="276" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/01.jpg" rel="lightbox"><img src="data:images/mini_01.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/02.jpg" rel="lightbox"><img src="data:images/mini_02.jpg" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/03.jpg" rel="lightbox"><img src="data:images/mini_03.jpg" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/04.jpg" rel="lightbox"><img src="data:images/mini_04.jpg" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/05.jpg" rel="lightbox"><img src="data:images/mini_05.jpg" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/06.jpg" rel="lightbox"><img src="data:images/mini_06.jpg" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/07.jpg" rel="lightbox"><img src="data:images/mini_07.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/08.jpg" rel="lightbox"><img src="data:images/mini_08.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" align="center"><a title="photo by xixi" href="images/09.jpg" rel="lightbox"><img src="data:images/mini_09.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
</tr>
<tr>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/10.jpg" rel="lightbox"><img src="data:images/mini_10.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/11.jpg" rel="lightbox"><img src="data:images/mini_11.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/12.jpg" rel="lightbox"><img src="data:images/mini_12.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/13.jpg" rel="lightbox"><img src="data:images/mini_13.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/14.jpg" rel="lightbox"><img src="data:images/mini_14.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/15.jpg" rel="lightbox"><img src="data:images/mini_15.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/16.jpg" rel="lightbox"><img src="data:images/mini_16.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/17.jpg" rel="lightbox"><img src="data:images/mini_17.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" align="center"><a title="photo by xixi" href="images/18.jpg" rel="lightbox"><img src="data:images/mini_18.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
</tr>
<tr>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/19.jpg" rel="lightbox"><img src="data:images/mini_19.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/20.jpg" rel="lightbox"><img src="data:images/mini_20.jpg" name="picboder" width="60" height="60" border="0" id="picboder"/></a></td>
<td width="86" height="86" align="center"><a title="photo by xixi" href="images/21.jpg" rel="lightbox"><img src="data:images/mini_21.jpg" name="picboder" width="60" height="60" border="0" id="picboder" /></a></td>
<td width="86" height="86" align="center"></td>
<td width="86" height="86" align="center"></td>
<td width="86" height="86" align="center"></td>
<td width="86" height="86" align="center"></td>
<td width="86" height="86" align="center"></td>
<td width="86" height="86" align="center"></td>
</tr>
</table></td>
</tr>
</table>
Css样式表
#lightbox{
background-color:#fff;
padding: 0px;
}
#picboder{
border:#f4f4f4 6px solid;
}
#lightboxDetails{
font-size: 0.8em;
padding-top: 0.4em;
}
#lightboxCaption{ float: left; }
#keyboardMsg{ float: right; }
#closeButton{
top: 0px; right: 0px;
}
#lightbox img{ border: none; clear: both;}
#overlay img{ border: none; }
#overlay{background-color: #333;}
* html #overlay{
background-color: transparent;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="data:images/overlay.png", sizingMethod="scale");
}
js demo
var loadingImage = 'images/loading.gif';
var closeButton = 'images/close.gif';
function getPageScroll(){
var yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
}
arrayPageScroll = new Array('',yScroll)
return arrayPageScroll;
}
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
return;
}
}
//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
key = String.fromCharCode(keycode).toLowerCase();
if(key == 'x'){ hideLightbox(); }
}
//
// listenKey()
//
function listenKey () { document.onkeypress = getKey; }
//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
// prep objects
var objOverlay = document.getElementById('overlay');
var objLightbox = document.getElementById('lightbox');
var objCaption = document.getElementById('lightboxCaption');
var objImage = document.getElementById('lightboxImage');
var objLoadingImage = document.getElementById('loadingImage');
var objLightboxDetails = document.getElementById('lightboxDetails');
var arrayPageSize = getPageSize();
var arrayPageScroll = getPageScroll();
// center loadingImage if it exists
if (objLoadingImage) {
objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
objLoadingImage.style.left = (((arrayPageSize[0] - 45 - objLoadingImage.width) / 2) + 'px');
objLoadingImage.style.display = 'block';
}
// set height of Overlay to take up whole page and show
objOverlay.style.height = (arrayPageSize[1] + 'px');
objOverlay.style.display = 'block';
// preload image
imgPreload = new Image();
imgPreload.onload=function(){
objImage.src = objLink.href;
// center lightbox and make sure that the top and left values are not negative
// and the image placed outside the viewport
var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
var lightboxLeft = ((arrayPageSize[0] - 9 - imgPreload.width) / 2);
objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
objLightboxDetails.style.width = imgPreload.width + 'px';
if(objLink.getAttribute('title')){
objCaption.style.display = 'block';
//objCaption.style.width = imgPreload.width + 'px';
objCaption.innerHTML = objLink.getAttribute('title');
} else {
objCaption.style.display = 'none';
}
// A small pause between the image loading and displaying is required with IE,
// this prevents the previous image displaying for a short burst causing flicker.
if (navigator.appVersion.indexOf("MSIE")!=-1){
pause(250);
}
if (objLoadingImage) { objLoadingImage.style.display = 'none'; }
// Hide select boxes as they will 'peek' through the image in IE
selects = document.getElementsByTagName("select");
for (i = 0; i != selects.length; i++) {
selects[i].style.visibility = "hidden";
}
objLightbox.style.display = 'block';
// After image is loaded, update the overlay height as the new image might have
// increased the overall page height.
arrayPageSize = getPageSize();
objOverlay.style.height = (arrayPageSize[1] + 'px');
// Check for 'x' keypress
listenKey();
return false;
}
imgPreload.src = objLink.href;
}
//
// hideLightbox()
//
function hideLightbox()
{
// get objects
objOverlay = document.getElementById('overlay');
objLightbox = document.getElementById('lightbox');
// hide lightbox and overlay
objOverlay.style.display = 'none';
objLightbox.style.display = 'none';
// make select boxes visible
selects = document.getElementsByTagName("select");
for (i = 0; i != selects.length; i++) {
selects[i].style.visibility = "visible";
}
// disable keypress listener
document.onkeypress = '';
}
//
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
function initLightbox()
{
if (!document.getElementsByTagName){ return; }
var anchors = document.getElementsByTagName("a");
// loop through all anchor tags
for (var i=0; i<anchors.length; i++){
var anchor = anchors[i];
if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
anchor.onclick = function () {showLightbox(this); return false;}
}
}
// the rest of this code inserts html at the top of the page that looks like this:
//
// <div id="overlay">
// <a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a>
// </div>
// <div id="lightbox">
// <a href="#" onclick="hideLightbox(); return false;" title="Click anywhere to close image">
// <img id="closeButton" />
// <img id="lightboxImage" />
// </a>
// <div id="lightboxDetails">
// <div id="lightboxCaption"></div>
// <div id="keyboardMsg"></div>
// </div>
// </div>
var objBody = document.getElementsByTagName("body").item(0);
// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
var objOverlay = document.createElement("div");
objOverlay.setAttribute('id','overlay');
objOverlay.onclick = function () {hideLightbox(); return false;}
objOverlay.style.display = 'none';
objOverlay.style.position = 'absolute';
objOverlay.style.top = '0';
objOverlay.style.left = '0';
objOverlay.style.zIndex = '90';
objOverlay.style.width = '100%';
objBody.insertBefore(objOverlay, objBody.firstChild);
var arrayPageSize = getPageSize();
var arrayPageScroll = getPageScroll();
// preload and create loader image
var imgPreloader = new Image();
// if loader image found, create link to hide lightbox and create loadingimage
imgPreloader.onload=function(){
var objLoadingImageLink = document.createElement("a");
objLoadingImageLink.setAttribute('href','#');
objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
objOverlay.appendChild(objLoadingImageLink);
var objLoadingImage = document.createElement("img");
objLoadingImage.src = loadingImage;
objLoadingImage.setAttribute('id','loadingImage');
objLoadingImage.style.position = 'absolute';
objLoadingImage.style.zIndex = '150';
objLoadingImageLink.appendChild(objLoadingImage);
imgPreloader.onload=function(){}; // clear onLoad, as IE will flip out w/animated gifs
return false;
}
imgPreloader.src = loadingImage;
// create lightbox div, same note about styles as above
var objLightbox = document.createElement("div");
objLightbox.setAttribute('id','lightbox');
objLightbox.style.display = 'none';
objLightbox.style.position = 'absolute';
objLightbox.style.zIndex = '100';
objBody.insertBefore(objLightbox, objOverlay.nextSibling);
// create link
var objLink = document.createElement("a");
objLink.setAttribute('href','#');
objLink.setAttribute('title','Click to close');
objLink.onclick = function () {hideLightbox(); return false;}
objLightbox.appendChild(objLink);
// preload and create close button image
var imgPreloadCloseButton = new Image();
// if close button image found,
imgPreloadCloseButton.onload=function(){
//var objCloseButtonDIV=document.createElement("div");
//objCloseButtonDIV.setAttribute('id','closeButton');
//objCloseButtonDIV.innerHTML='';
var objCloseButton = document.createElement("img");
objCloseButton.src = closeButton;
objCloseButton.setAttribute('id','closeButton');
objCloseButton.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/close.png', sizingmethod=scale);"
objCloseButton.style.position = 'absolute';
objCloseButton.style.zIndex = '200';
//objCloseButtonDIV.appendChild(objCloseButton);
//alert(objCloseButton.style.filter);
objLink.appendChild(objCloseButton);
//return false;
}
imgPreloadCloseButton.src = closeButton;
// create image
var objImage = document.createElement("img");
objImage.setAttribute('id','lightboxImage');
objLink.appendChild(objImage);
// create details div, a container for the caption and keyboard message
var objLightboxDetails = document.createElement("div");
objLightboxDetails.setAttribute('id','lightboxDetails');
objLightbox.appendChild(objLightboxDetails);
// create caption
var objCaption = document.createElement("div");
objCaption.setAttribute('id','lightboxCaption');
objCaption.style.display = 'none';
objLightboxDetails.appendChild(objCaption);
// create keyboard message
var objKeyboardMsg = document.createElement("div");
objKeyboardMsg.setAttribute('id','keyboardMsg');
objKeyboardMsg.innerHTML = 'press <kbd>x</kbd> to close';
objLightboxDetails.appendChild(objKeyboardMsg);
}
//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function'){
window.onload = func;
} else {
window.onload = function(){
oldonload();
func();
}
}
源地址:http://niutuku.com/
图片展示js特效的更多相关文章
- 超酷动态图片展示墙JS特效制作方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JS实现有点炫的图片展示效果-图片解体和组合
经过4个月的努力学习,迎来了进入市场的最后一个学习项目.自己模仿了一个图片展示效果,用在了项目中,感觉挺炫的.在这里分享一下,希望大家喜欢~! bomb-showImg : 在线演示http://ru ...
- JS框架_(coolShow.js)图片旋转动画特效
百度云盘 传送门 密码:ble6 coolShow.js插件图片旋转动画效果 <!DOCTYPE HTML> <head> <meta http-equiv=" ...
- openseadragon.js与deep zoom java实现艺术品图片展示
openseadragon.js 是一款用来做图像缩放的插件,它可以用来做图片展示,做展示的插件很多,也很优秀,但大多数都解决不了图片尺寸过大的问题. 艺术品图像展示就是最简单的例子,展示此类图片一般 ...
- 带左右箭头切换的自动滚动图片JS特效
效果图 按钮 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- 原生js和jquery实现图片轮播特效
本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...
- java+js实现完整的图片展示本地目录demo
java+js实现完整的图片展示本地目录demo 最近的项目满足需要,实现通过一个前端button点击事件,流行音乐浏览下的全部图片: 思路: - 获取到所需展示图片的本地目录内全部图片的文件绝对路径 ...
- 原生js和jquery实现图片轮播特效(转)
本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...
- jq图片展示插件highslide.js简单dom
今天用用了一款图片展示插件highslide.js,感觉用起来很是舒畅,几乎不用怎么写代码,只需要知道如何写参数就行了. 那么这么牛叉的插件我们该如何用哪,下面我就跟大家讲解一下. 一.引入 首先 ...
随机推荐
- Python利用itchat库向好友或者公众号发消息
首先获得好友或者公众号的UserName 1.获取好友UserName #coding=utf8 import itchat itchat.auto_login(hotReload=True) #想给 ...
- 聊聊WPF中的Dispatcher
DispatcherObject,Dispatcher,Thread之间的关系 我们都知道WPF中的控件类都是从System.Windows.Threading.DispatcherObject继承而 ...
- 蓝桥杯 算法训练 ALGO-152 8-2求完数
算法训练 8-2求完数 时间限制:50.0s 内存限制:256.0MB 问题描述 如果一个自然数的所有小于自身的因子之和等于该数,则称为完数.设计算法,打印1-9999之间的所有完数. 样例 ...
- 本地测试html文件时CSS效果显示, 但是当django的服务器上运行时效果不显示
本地测试时各种效果都显示, 但是当在django服务器上测试时, 效果却不显示, 原因是我将css文件放在一个static文件夹里, 没有在settings中设置static_dir选项.将stati ...
- 部署和调优 1.8 samba 部署和优化-2
Samba 可以实现 Linux 和 Windows 机器相互共享文件,这对我们来说是非常实用的.下面做几个实践,来了解samba,注意:在实践之前,请先检测 Selinux 是否关闭,否则可能会实践 ...
- 解决Xcode在debug时不在断点处停止的方法<转>
搞了老半天不知道为什么 后来查了一下才解决问题,多谢原创作者的贡献. 新年后的第一发! -------------------------------- 前几天在开发的时候,Xcode设置断点后依然无 ...
- 使用网络用户命令行工具的/passwordreq:yes
提示:"新建域时,本地administrator帐户将成为域administrator账户.无法新建域,因为本地administrator账户密码不符合要求.目前,本地administrat ...
- 2-2 zookeeper下载、安装以及配置环境变量
https://archive.apache.org/dist/zookeeper/zookeeper-3.4.11/ FTP的软件:FileZilla Client 登录腾讯云服务器tail /va ...
- c++11: thread_local
thread_local变量是C++ 11新引入的一种存储类型.它会影响变量的存储周期(Storage duration),C++中有4种存储周期: automatic static dynamic ...
- ueditor 1.2.6使用方法
本文以php版本为例: 文件下载:http://ueditor.baidu.com/website/download.html 还可以自己先定义内容,然后下载,这样可以帮助我们精简不少东西. 以本地p ...