`
htj1231825
  • 浏览: 38521 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jquery图片动态加载示例

阅读更多
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片动态加载示例</title>
<style type="text/css">
img{border:0;}
a{cursor:pointer;color:#014ccc;text-decoration:underline;}
a:hover{text-decoration:none;}
.clear{clear:both;height:0px;overflow:hidden;}
.img_list{margin:0 auto;}
.img_list li{list-style:none}
.img_list .items{width:300px;margin:0 auto;}
.img_list .item{float:left;margin-bottom:5px;font-size:14px;}
.img_list .item .order{display:inline-block;*display:inline;*zoom:1;width:28px;color:#f30;}
.img_list .item .i_thumb{width:300px;height:280px;}
.img_list .item .i_title{width:100%;height:20px;}
.showmore{height:35px;background:#f8f8f8;border-bottom:1px solid #cccccc;cursor:pointer;tetx-align:center;margin-bottom:25px;}
.showmore .handle{display:block;height:35px;text-align:center;color:#909090;font-size:14px;text-decoration:none;line-height:35px;}
.showmore .handle:hover{text-decoration:none;background:#e6e6e6;}
</style>
<script type="text/javascript" src="images_test/jquery-1.4.4.min.js"></script>
</head>

<body>
<center><h1>图片动态加载示例</h1></center>
<div class="img_list" id="img_list">
  <div class="items" id="items">
    <ul class="item">
      <li class="i_thumb"><a href="http://www.xuekaifa.com" target="_blank" title="初 私房"><img src="images_test/1.jpg" alt="初 私房" /></a></li>
      <li class="i_title"><span class="order">1</span><a href="http://www.xuekaifa.com" target="_blank" title="初 私房">初 私房</a></li>
    </ul>

    <ul class="item">
      <li class="i_thumb"><a href="http://www.xuekaifa.com" target="_blank" title="初 私房"><img src="images_test/2.jpg" alt="初 私房" /></a></li>
      <li class="i_title"><span class="order">2</span><a href="http://www.xuekaifa.com" target="_blank" title="初 私房">初 私房</a></li>
    </ul>
					
    <ul class="item">
      <li class="i_thumb"><a href="http://www.xuekaifa.com" target="_blank" title="初 私房"><img src="images_test/3.jpg" alt="初 私房" /></a></li>
      <li class="i_title"><span class="order">3</span><a href="http://www.xuekaifa.com" target="_blank" title="初 私房">初 私房</a></li>
    </ul>
					
    <ul class="item">
      <li class="i_thumb"><a href="http://www.xuekaifa.com" target="_blank" title="初 私房"><img src="images_test/4.jpg" alt="初 私房" /></a></li>
      <li class="i_title"><span class="order">4</span><a href="http://www.xuekaifa.com" target="_blank" title="初 私房">初 私房</a></li>
    </ul>
					
    <div class="clear"></div>
  </div>
					
  <div class="showmore" id="showmore" ><a class="handle" href="javascript:show()">显示更多结果</a></div>
	
</div>

<script type="text/javascript">
var iHeight = 0;
var iTop = 0;
var clientHeight = 0;
var iIntervalId = null;
var itemsSize = 0;
var pageNo = 1;   // 当前页数,默认设为第 1 页
var pageSize = 4; // 每页显示的数量

getPageHeight();

// 添加定时检测事件,每2秒检测一次
iIntervalId = setInterval("_onScroll();", 2000);

// 取得当前页面显示所占用的高度
function getPageHeight() {
  if(document.body.clientHeight && document.documentElement.clientHeight) {  
    clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;          
  } else {  
    clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;      
  }

  iHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}

// 调用ajax取服务端数据
function show() {
  pageNo++;

  $.ajax({
    url: 'img.php?p='+pageNo+'&r='+Math.random(),
    type: 'GET',
    dataType: 'text',
    timeout: 4000,
	beforeSend: showLoadingImg,
    error: showFailure,
    success: showResponse
  });
}

function showLoadingImg() {
  $('#showmore').html('<a class="handle" href="javascript:show()"><img src="images_test/loading.gif" height="32px" />显示更多结果</a>');
}

function showFailure() {
  $('#showmore').html('<font color=red> 获取查询数据出错 </font>');
}

// 根据ajax取出来的json数据转换成html
function showResponse(responseData) {
  var returnjson = eval("("+responseData+")");
  itemsSize = returnjson.items.length;

  var nextpagehtml = '';
  var pageOffset = (pageNo-1)*pageSize + 1;
  for(i=0; i<itemsSize; i++) {
    nextpagehtml +=	'<ul class="item">';
    nextpagehtml +=	'<li class="i_thumb"><a href="http://www.xuekaifa.com" target="_blank" title="'+ returnjson.items[i].name +'"><img src="'+ returnjson.items[i].pic +'" alt="'+ returnjson.items[i].name +'" /></a></li>';
    nextpagehtml +=	'<li class="i_title"><span class="order">'+ (pageOffset + i) +'</span><a href="http://www.xuekaifa.com" target="_blank" title="'+ returnjson.items[i].name +'">'+ returnjson.items[i].name +'</a></li>';			
						
    nextpagehtml +=	'</ul>';
  }
  nextpagehtml += '<div class="clear"></div>';
  $('#items').html($('#items').html() + nextpagehtml);

  // 当前页码数小于3页时继续显示更多提示框
  if(pageNo < 3) {
    $('#showmore').html('<a class="handle" href="javascript:show()">显示更多结果</a>');
  } else {
    clearInterval(iIntervalId);
    $('#showmore').hide();
  }
}

// 判断滚动条是否到达底部
function reachBottom() {
  var scrollTop = 0;
  if(document.documentElement && document.documentElement.scrollTop) {  
    scrollTop = document.documentElement.scrollTop;  
  } else if (document.body) {  
    scrollTop = document.body.scrollTop;  
  }
  if((scrollTop > 0) && (scrollTop + clientHeight == iHeight)) {
    return true;  
  } else {  
    return false; 
  }
}

// 检测事件,检测滚动条是否接近或到达页面的底部区域,0.99是为了更接近底部时
function _onScroll() {
  iTop = document.documentElement.scrollTop + document.body.scrollTop;
  getPageHeight();
  if(((iTop+clientHeight)>parseInt(iHeight*0.99))||reachBottom()) {
    if(pageNo >= 3) {
      clearInterval(iIntervalId);
      $('#showmore').hide();
      return;
    }
    show();
  }
};
</script>

</body>
</html>


分享到:
评论

相关推荐

    jQuery+ajax实现动态添加表格tr td功能示例

    主要介绍了jQuery+ajax实现动态添加表格tr td功能,结合实例形式分析了jQuery基于ajax动态创建页面table元素相关操作技巧,需要的朋友可以参考下

    jquery 动态示例

    18. jQuery图片插件之鼠标放在图片上出现动态的hover效果插件 19. jQuery图片自动轮播淡入淡出的幻灯插件iFadeSlide 20. jQuery大气banner带时间线自动播放的焦点图轮番切换代码 21. jquery定时自动切换banner...

    非常漂亮的100个 jquery前端案例,包含幻灯片切换、图片缩放、相册、放大镜、图片拖着滚动等.zip

    jQuery图片插件之鼠标放在图片上出现动态的hover效果插件 jQuery图片特效404 jQuery图片特效CustomAnimationBanner jQuery图片特效FullPageImageGallery jQuery图片特效image Scroller图片滚动 jQuery图片特效...

    jquery动态添加option示例

    jquery动态添加option js动态添加option 代码如下:var sel= document.getElementById(“Selected1”); sel.options.add(new Option(“请选择”,””));sel.options.add(new Option(“name”,”id”)); jquery...

    jQuery实现动态加载select下拉列表项功能示例

    本文实例讲述了jQuery实现动态加载select下拉列表项功能。分享给大家供大家参考,具体如下: 需求说明: 以前使用的select下拉列表都是静态的,select 的option数据都是写死的。现在项目中的select需要根据不同的...

    example-jquery-shim, 通过shim配置使用jQuery和jQuery插件的示例项目.zip

    example-jquery-shim, 通过shim配置使用jQuery和jQuery插件的示例项目 在 shim 配置中使用jQuery和 ... jQuery本身寄存器加载jQuery和jQuery插件的方法,可以以轻松加载。 然而,大多数插件并不像AMD模块那样 regi

    100多个JQuery效果示例(实例)div+css+javascrpit

    101. 打包基于jQuery对图片边框修饰插件示例下载(支持图片阴影效果、顶部banner效果、邮票边框、毛边相框、云朵包围效果) 102. 推荐jquery仿Flash大banner图片切换播放特效,非常完美 103. 推荐jQuery仿新浪QQ绝好...

    JavaScript_JQuery_CSS_CSS_DIV漂亮的实例123个

    101. 打包基于jQuery对图片边框修饰插件示例下载(支持图片阴影效果、顶部banner效果、邮票边框、毛边相框、云朵包围效果) 102. 推荐jquery仿Flash大banner图片切换播放特效,非常完美 103. 推荐jQuery仿新浪QQ绝...

    jquery图片浏览例子

    jquery练习小例子,本例中使用了jquery添加节点,修改节点样式,操作节点的dom属性,还有用jquery实现的动画。

    jquery动态加载select下拉框示例代码

    jquery实现动态加载select下拉选项&lt;/title&gt; [removed] function init(){ makemoduleSelect(); } //加载模板下拉框选项 function makemoduleSelect(){ $.ajax({ url : ‘indexStatisticsAction_getSelect.jsp’...

    jQuery实现动态添加节点与遍历节点功能示例

    主要介绍了jQuery实现动态添加节点与遍历节点功能,结合实例形式分析了jQuery针对页面元素节点元素的动态添加与遍历相关操作技巧,需要的朋友可以参考下

    jquery图片延迟加载

    插件描述:不有添加多余的属性值,直接设src属性值就ok. 参考示例:http://www.jq22.com/jquery-info5133

    jquery Reflex.js 图片倒影插件附示例.rar

    开源代码之:jquery Reflex.js 图片倒影插件附示例,自动为你显示在网页上的图片添加倒影效果,核心代码基于Reflex.js ,内含效果演示和用法文档,效果如演示截图所示。

    JavaScript_JQuery_CSS_DIV漂亮的实例

    18. jQuery图片插件之鼠标放在图片上出现动态的hover效果插件 19. jQuery图片自动轮播淡入淡出的幻灯插件iFadeSlide 20. jQuery大气banner带时间线自动播放的焦点图轮番切换代码 21. jquery定时自动切换banner...

    php+jquery+mysql完整添加删除示例

    演示基本操作,没用其他插件,适合新手学习用,理解jquery的用法。

    jquery.json-viewer示例

    在原jquery.json-viewer的示例基础上添加了key(关键字)加粗,解压点击即可运行

    jquery实现加载等待效果示例

    加载等待效果想必大家都有见到过吧,其实很简单,在本文将为大家介绍下使用jquery是如何实现的,感兴趣的朋友可以参考下

Global site tag (gtag.js) - Google Analytics