焦点图

帅比萌擦擦* 提交于 2019-12-17 10:25:43

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 2 <html xmlns="http://www.w3.org/1999/xhtml"> 
 3 <head> 
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
 5 <title>JQuery实现图片轮播效果 </title> 
 6 <script src="http://img.jb51.net/jslib/jquery/jquery14.js" type="text/javascript"></script> 
 7 <style type="text/css"><!-- 
 8 #banner {position:relative; width:478px; height:286px; border:1px solid #666; overflow:hidden; font-size:16px} 
 9 #banner_list img {border:0px;} 
10 
11 #banner_text {position:absolute;width:120px;z-index:1002; right:3px; bottom:3px;} 
12 #banner ul {position:absolute;list-style-type:none;filter: Alpha(Opacity=80);opacity:0.8; z-index:1002; 
13 margin:0; padding:0; bottom:3px; right:5px; height:20px} 
14 #banner ul li { padding:0 8px; line-height:18px;float:left;display:block;color:#FFF;border:#e5eaff 1px solid;background-color:#6f4f67;cursor:pointer; margin:0; font-size:16px;} 
15 #banner_list a{position:absolute;} <! 让四张图片都可以重叠在一起 
16 --></style> 
17 </head> 
18 
19 <body> 
20 
21 
22 <div id="banner"> 
23 
24 
25 <ul> 
26 <li>1</li> 
27 <li>2</li> 
28 <li>3</li> 
29 <li>4</li> 
30 </ul> 
31 <div id="banner_list"> 
32 <a href="#" target="_blank"><img src="http://files.jb51.net/demoimg/201008/o_p1.jpg" title="橡树小屋的blog" alt="橡树小屋的blog" /></a> 
33 <a href="#" target="_blank"><img src="http://files.jb51.net/demoimg/201008/o_p3.jpg" title="橡树小屋的blog" alt="橡树小屋的blog" /></a> 
34 <a href="#" target="_blank"><img src="http://files.jb51.net/demoimg/201008/o_p4.jpg" title="橡树小屋的blog" alt="橡树小屋的blog" /></a> 
35 <a href="#" target="_blank"><img src="http://files.jb51.net/demoimg/201008/o_p5.jpg" title="橡树小屋的blog" alt="橡树小屋的blog" /></a> 
36 </div> 
37 </div> 
38 <script type="text/javascript">
39 
40 $(document).ready(function(){
41     
42     var t = n = 0, count;  
43 count=$("#banner_list a").length; 
44 
45 
46 $("#banner_list a:not(:first-child)").hide(); 
47 
48 
49 $("#banner li").click(function() { 
50 var i = $(this).text() - 1;//获取Li元素内的值,即1,2,3,4 
51 n = i; 
52 if (i >= count) return; 
53 
54 
55 $("#banner_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000); 
56 $(this).css({"background":"#be2424",'color':'#000'}).siblings().css({"background":"#6f4f67",'color':'#fff'}); 
57 
58 
59 }); 
60 
61 
62 
63 t = setInterval(showAuto, 4000);
64  
65 $("#banner").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 4000);});
66 
67 
68 function showAuto() 
69 { 
70 n = n >=(count - 1) ? 0 : ++n; 
71 $("#banner li").eq(n).trigger('click'); 
72 } 
73 
74  
75 }) 
76 
77 
78 </script> 
79 </body> 
80 </html> 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!