The Image Gallery Revisited
Lets apply the Best practices to the Image Gallery .
/*** index.html ***/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Gallery</title>
<link rel="stylesheet" href="styles/layout.css" media="screen">
</head>
<body> <h1>Snapshiots</h1>
<ul id="imagegallery">
<li>
<a href="images/fireworks.jpg" title="A fireworks display"> Fireworks </a>
</li>
<li>
<a href="images/coffee.jpg" title="A cup of black coffe"> Coffee </a>
</li>
<li>
<a href="images/rose.jpg" title="A red, red rose"> Rose </a>
</li>
<li>
<a href="images/bigben.jpg" title="The famous clock"> Big Ben </a>
</li>
</ul>
<div id="placeholder">
<img src="data:images/placeholder.gif" alt="my image gallery" >
</div>
<div id="description">
<p>Choose an image</p>
</div> <script type="text/javascript" src="scripts/showPic.js"></script> <script type="application/javascript">
// alert (description.childNodes.length);
// window.onload = countBodyChildren;
//var description = document.getElementById("description");
//alert (description.childNodes[2].nodeValue);
</script>
</body>
</html>
/*** showPic.js ***/
/**
* Created by Administrator on 9/9/2015.
*/ function addLoadEvent(func) {
var oldonload = window.onload;
if( typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
} function prepareGallery() {
if( !document.getElementsByTagName ) return false;
if( !document.getElementById ) return false;
if( !document.getElementById("imagegallery") ) return false; var gallery = document.getElementById("imagegallery");
var links = gallery.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
links[i].onclick = function() {
return showPic(this) ? false : true;
}
}
} /*
you can use this function to count how many children nodes the body element contains
*/
function countBodyChildren() {
var body_element = document.getElementsByTagName("body")[0];
alert(body_element.nodeType);
alert( body_element.childNodes.length );
} function showPic(whicPic) {
if( !document.getElementsByTagName ) return false;
if( !document.getElementById("placeholder") ) return false;
var source = whicPic.getAttribute("href"); var placeholder = document.getElementById("placeholder");
var img = placeholder.getElementsByTagName("img")[0];
img.setAttribute("src", source);
if(document.getElementById("description")) {
var text = whicPic.getAttribute("title") ? whicPic.getAttribute("title") : 3;
var description = document.getElementById("description");
var desc_p = description.getElementsByTagName("p")[0];
desc_p.firstChild.nodeValue = text;
}
return true;
} addLoadEvent( prepareGallery );
/*** layout.css ***/
body{
font-family: "Helvetica", "Arial", serif;
color: #333;
background-color: #ccc;
margin: 1em 10%;
} h1{
color: #333;
/*background-color: #777;*/
} a{
color: #c60;
background-color: transparent;
font-weight: bold;
text-decoration: none;
} ul{
padding:;
} li{
float: left;
padding: 1em;
list-style: none;
} img {
display: block;
clear: both;
}
I think there is a function you can use in the furture, thats the addLoadEvent() :
function addLoadEvent(func) {
var oldonload = window.onload;
if( typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
This is a good plan for the future expansion.
This effectively creates a queue of functions to be executed when the page loads.
The Image Gallery Revisited的更多相关文章
- 使用图片视频展示插件blueimp Gallery改造网站的视频图片展示
在很多情况下,我们网站可能会展示我们的产品图片.以及教程视频等内容,结合一个比较好的图片.视频展示插件,能够使得我们的站点更加方便使用,也更加酷炫,在Github上有很多相关的处理插件可以找来使用,有 ...
- 备忘-Android ViewPager 与Gallery滑动冲突解决方法
解决方法,重新定义gallery,禁止触发pager的触摸事件 1 public class UserGallery extends Gallery implements OnGestureListe ...
- Android Gallery
xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- S Gallery – 很有特色的响应式 jQuery 相册插件
S Gallery 是一款响应式的 jQuery 相册插件.使用了 HTML5 全屏 API 以及 CSS3 动画 和 CSS3 转换,所以只能在支持这些功能的浏览器中使用. 这款插件它有一个特色功能 ...
- 解决在android开发中ViewPager中Gallery无法滑动问题
我的是在viewpager中某个fragment中有gallery... 导致无法滑动,网上找到解决方法. 自定义Gallery. 代码: import android.content.Context ...
- 25个最佳的 WordPress Gallery 画廊插件
WordPress 画廊插件最适合用于作品展示网站,特别对于那些想以一个奇特的,现代的方式展示他们作品的摄影师.如果你想为你安装 WordPress Gallery 插件,那么下面的是你想要的. 本文 ...
- Android 从Gallery获取图片
本文主要介绍Android中从Gallery获取图片 设计项目布局 <LinearLayout xmlns:android="http://schemas.android.com/ap ...
- Android -- ImageSwitch和Gallery 混合使用
1. 实现效果
- jQuery插件实现图片展开效果,jquery.gallery。仿腾讯QQ空间说说图片展示效果。
公司的项目http://www.umfun.com/,有个说说的页面(和腾讯QQ空间说说一样),里面有个发表图片功能,上传完图片,需要点击展开的效果. 当时手里面事情比较多(公司就我一个前端),忙不过 ...
随机推荐
- C++ Knowledge series STL & Const
Thank to the pepole who devote theirself to the common libs. STL(http://www.cplusplus.com/reference/ ...
- 我的Android开发之路——百度地图开源工具获取定位信息
定位技术在现在的移动设备上是必不可少的,许多app都会使用定位功能. 通常定位方式有两种:GPS定位:网络定位. Android系统对这两种定位方式都提供了相应的API支持,但是因为google的网络 ...
- SpringMVC ------JstlView
摘要: Spring为展现层提供的基于MVC设计理念的优秀的Web框架,是目前最主流的MVC框架之一 .Spring3.0后全面超越Struts,成为最优秀的MVC框架 .SpringMVC通过一套M ...
- Python基础学习之变量赋值
1.赋值操作符 Python语言中,等号(=)是主要的赋值操作符: >>> aInt=-100 >>> aString='this is a string' > ...
- c++为什么定义了析构函数的类的operator new[]传入的参数会多4字节?
问题: 在网上看人写了这么一段代码: class A { public: A() { std::cout<<"call A constructor"<< ...
- leetcode: 数组
1. longest-consecutive-sequence Given an unsorted array of integers, find the length of the longest ...
- 安装和使用nmon监测hadoop集群性能
nmon是一个非常易用的监测Unix/Linux系统性能的小工具,可以在一个屏幕上通过指令切换,显示几乎你想要的所有指标,并且可以自动将指标周期性的保存成 .nmon格式文件,这个工具可以与nmon_ ...
- sql server 拆分字符串,拆分两次(:和;)
declare @DisciplineID int declare @paramStringVal nvarchar() declare @NPNT nvarchar() declare @Disci ...
- 使用jdk进行数据迁移(sqlite迁移mysql)
直接粘贴代码 注意:rewriteBatchedStatements=true(加快连接速度) package com.wbg; import org.omg.Messaging.SYNC_WITH_ ...
- p2597 灾难
我的思路 代码: #include<cstdio> #include<iostream> #include<algorithm> #include<vecto ...