写了一个简单轮播效果实现
2017-05-05 21:06
447 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> html,body{height:100%;} *{margin:0;padding:0;} .box{ width:100%; height:100%; text-align:center; } a{ text-decoration:none; } .box .btn{ display:inline-block; color:#abcdef; width:80px; height:40px; text-align:center; line-height:40px; } .box .btn:hover{ background:#ddd; color:#fff; } .box img{display:none;} .loading{ position:fixed; width:100%; height:100%; text-align:center; left:0; top:0; background:#ddd; font-size:30px; color:#555; display:block; } .loading .loading-text{ margin-top:300px; } </style> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script> </head> <body> <div id="page" class="box"> <img src="http://img.mukewang.com/58fcb33800011b4b12000460.jpg" alt=""> <div class="cruent"> <a href="javascript:;" class="btn prev">上一页</a> <a href="javascript:;" class="btn next">下一页</a> </div> </div> <div class="loading"> <div class="loading-text">0%</div> </div> <script> $(function(){ var arr = ["http://img.mukewang.com/58fcb33800011b4b12000460.jpg", "http://img.mukewang.com/5903646e00011baa12000460.jpg","http://img.mukewang.com/5903653d0001041812000460.jpg","http://img.mukewang.com/58f893ae00010ef612000460.jpg"]; var index = 0; var count = 0; $.each(arr,function(i,val){ var loadImg = new Image(); $(loadImg).on("load error",function(){ $(".loading-text").html(Math.round((count+1)/arr.length*100)+"%"); }) loadImg.src = val; if(count >= arr.length-1){ $(".loading").hide(); $(".box").find("img").eq(index).show(); } count++; }) $('.prev').on('click',function(){ ++index; if(index > arr.length-1){ index = 0; } $(".box").find("img").attr("src",arr[index]); }) $(".next").on("click",function(){ --index; if(index<0){ index = arr.length-1; } $(".box").find("img").attr("src",arr[index]); }) }) </script> </body> </html>
相关文章推荐
- js 实现一个简单的3D轮播效果
- jQuery实现一个简单的选项卡效果
- 一个js实现简单的字幕滚动效果
- 代码录播:jQueryMobile 实现一个简单的弹出框效果
- Android:实现一个带动画轮播效果的公告条。
- viewPager+Handler+Timer简单实现广告轮播效果
- Tab切换动画滑动效果的一个简单实现
- 调用MyFocus库,简单实现二十几种轮播效果
- Canvas画板实现一个简单的球在盒子内随机移动效果
- js/html/css做一个简单的图片自动(auto)轮播效果//带注释
- JQuery实现一个简单的鼠标跟随提示效果
- css3和jQuery实现一个简单的标签页效果
- html5实现的一个简单的下雨效果
- 代码录播:jQueryMobile 实现一个简单的弹出框效果
- C#实现一个图形的动态效果(简单矩形不断向下运动的实现简单步骤)
- 想给自己制作一个简单的相册吗?快来看看 怎样实现3D图片相册效果
- Unity3d 一个简单的玻璃效果实现!
- 用jquery做一个简单的图片轮播效果
- JQuery简单实现图片轮播效果
- Android之——史上最简单图片轮播广告效果实现