首页 > 学院 > 开发设计 > 正文

HTML中动态图片切换JQuery实现

2019-11-17 01:34:58
字体:
来源:转载
供稿:网友

HTML中动态图片切换JQuery实现

相信很多同学都注意到了,各大新闻或者娱乐网站都含有动态图片切换,那个漂亮的感觉让刚刚学习html的人,都非常好奇和心动。那下面就让我们看一下到底如何实现动态图片切换呢?看一下百度贴吧的效果图吧~

javascript代码
Javascript代码
  1. //JavaScriptDocument
  2. vart=count=n=0;
  3. $(function(){
  4. $(".big_imga:not(:first)").hide();
  5. $(".link_nava:not(:first)").hide();
  6. $num_nav=$(".num_navspan");
  7. $big_img=$(".big_imga");
  8. count=$big_img.length;
  9. t=setInterval("showAuto()",3000);
  10. $num_nav.click(function(){
  11. varnum_nav=$(".num_navspan").index(this);
  12. $(this).addClass("selected").siblings().removeClass("selected");
  13. $big_img.filter(":visible").fadeOut(500).parent().children().eq(num_nav).fadeIn(1000);
  14. $(".link_nava").filter(":visible").fadeOut(500).parent().children().eq(num_nav).fadeIn(1000);
  15. });
  16. $(".img_nav").hover(function(){clearInterval(t)},function(){t=setInterval("showAuto()",3000);});
  17. })
  18. functionshowAuto()
  19. {
  20. n=n>=2?0:(n+1);
  21. $num_nav.eq(n).trigger('click');
  22. }

Javascript代码
  1. /*!
  2. *jQueryJavaScriptLibraryv1.3.1
  3. *http://jquery.com/
  4. *
  5. *Copyright(c)2009JohnResig
  6. *DuallicensedundertheMITandGPLlicenses.
  7. *http://docs.jquery.com/License
  8. *
  9. *Date:2009-01-2120:42:16-0500(Wed,21Jan2009)
  10. *Revision:6158
  11. */
  12. (function(){
  13. var
  14. //WillspeeduPReferencestowindow,andallowsmungingitsname.
  15. window=this,
  16. //Willspeedupreferencestoundefined,andallowsmungingitsname.
  17. undefined,
  18. //MapoverjQueryincaSEOfoverwrite
  19. _jQuery=window.jQuery,
  20. //Mapoverthe$incaseofoverwrite
  21. _$=window.$,
  22. jQuery=window.jQuery=window.$=function(selector,context){
  23. //ThejQueryobjectisactuallyjusttheinitconstructor'enhanced'
  24. returnnewjQuery.fn.init(selector,context);
  25. },
  26. //AsimplewaytocheckforHTMLstringsorIDstrings
  27. //(bothofwhichweoptimizefor)
  28. quickExpr=/^[^<]*(<(.|/s)+>)[^>]*$|^#([/w-]+)$/,
  29. //Isitasimpleselector
  30. isSimple=/^.[^:#/[/.,]*$/;
  31. jQuery.fn=jQuery.prototype={
  32. init:function(selector,context){
  33. //Makesurethataselectionwasprovided
  34. selector=selector||document;
  35. //Handle$(DOMElement)
  36. if(selector.nodeType){
  37. this[0]=selector;
  38. this.length=1;
  39. this.context=selector;
  40. returnthis;
  41. }
  42. //HandleHTMLstrings
  43. if(typeofselector==="string"){
  44. //ArewedealingwithHTMLstringoranID?
  45. varmatch=quickExpr.exec(selector);
  46. //Verifyamatch,andthatnocontextwasspecifiedfor#id
  47. if(match&&(match[1]||!context)){
  48. //HANDLE:$(html)->$(array)
  49. if(match[1])
  50. selector=jQuery.clean([match[1]],context);
  51. //HANDLE:$("#id")
  52. else{
  53. varelem=document.getElementById(match[3]);
  54. //HandlethecasewhereIEandOperareturnitems
  55. //bynameinsteadofID
  56. if(elem&&elem.id!=match[3])
  57. returnjQuery().find(selector);
  58. //Otherwise,weinjecttheelementdirectlyintothejQueryobject
  59. varret=jQuery(elem||[]);
  60. ret.context=document;
  61. ret.selector=selector;
  62. returnret;
  63. }
  64. //HANDLE:$(expr,[context])
  65. //(whichisjustequivalentto:$(content).find(expr)
  66. }else
  67. returnjQuery(context).find(selector);
  68. //HANDLE:$(function)
  69. //Shortcutfordocumentready
  70. }elseif(jQuery.isFunction(selector))
  71. returnjQuery(document).ready(selector);
  72. //Makesurethatoldselectorstateispassedalong
  73. if(selector.selector&&selector.context){
  74. this.selector=selector.selector;
  75. this.context=selector.context;
  76. }
  77. returnthis.setArray(jQuery.makeArray(selector));
  78. },
  79. //Startwithanemptyselector
  80. selector:"",
  81. //ThecurrentversionofjQuerybeingused
  82. jquery:"1.3.1",
  83. //Thenumberofelementscontainedinthematchedelementset
  84. size:function(){
  85. returnthis.length;
  86. },
  87. //GettheNthelementinthematchedelementsetOR
  88. //Getthewholematchedelementsetasacleanarray
  89. get:function(num){
  90. returnnum===undefined?
  91. //Returna'clean'array
  92. jQuery.makeArray(this):
  93. //Returnjusttheobject
  94. this[num];
  95. },
  96. //Takeanarrayofelementsandpushitontothestack
  97. //(returningthenewmatchedelementset)
  98. pushStack:function(elems,name,selector){
  99. //BuildanewjQuerymatchedelementset
  100. varret=jQuery(elems);
  101. //Addtheoldobjectontothestack(asareference)
  102. ret.prevObject=this;
  103. ret.context=this.context;
  104. if(name==="find")
  105. ret.selector=this.selector+(this.selector?"":"")+selector;
  106. elseif(name)
  107. ret.selector=this.selector+"."+name+"("+selector+")";
  108. //Returnthenewly-formedelementset
  109. returnret;
  110. },
  111. //Forcethecurrentmatchedsetofelementstobecome
  112. //thespecifiedarrayofelements(destroyingthestackintheprocess)
  113. //YoushouldusepushStack()inordertodothis,butmaintainthestack
  114. setArray:function(elems){
  115. //Resettingthelengthto0,thenusingthenativeArraypush
  116. //isasuper-fastwaytopopulateanobjectwitharray-likeproperties
  117. this.length=0;
  118. Array.prototype.push.apply(this,elems);
  119. returnthis;
  120. },
  121. //Executeacallbackforeveryelementinthematchedset.
  122. //(Youcanseedtheargumentswithanarrayofargs,butthisis
  123. //onlyusedinternally.)
  124. each:function(callback,args){
  125. returnjQuery.each(this,callback,args);
  126. },
  127. //Determinethepositionofanelementwithin
  128. //thematchedsetofelements
  129. index:function(elem){
  130. //Locatethepositionofthedesiredelement
  131. returnjQuery.inArray(
  132. //IfitreceivesajQueryobject,thefirstelementisused
  133. elem&&elem.jquery?elem[0]:elem
  134. ,this);
  135. },
  136. attr:function(name,value,type){
  137. varoptions=name;
  138. //Lookforthecasewherewe'reaccessingastylevalue
  139. if(typeofname==="string")
  140. if(value===undefined)
  141. returnthis[0]&&jQuery[type||"attr"](this[0],name);
  142. else{
  143. options={};
  144. options[name]=value;
  145. }
  146. //Checktoseeifwe'resettingstylevalues
  147. returnthis.each(function(i){
  148. //Setallthestyles
  149. for(nameinoptions)
  150. jQuery.attr(
  151. type?
  152. this.style:
  153. this,
  154. name,jQuery.prop(this,options[name],type,i,name)
  155. );
  156. });
  157. },
  158. CSS:function(key,value){
  159. //ignorenegativewidthandheightvalues
  160. if((key=='width'||key=='height')&&parseFloat(value)<0)
  161. value=undefined;
  162. returnthis.attr(key,value,"curCSS");
  163. },
  164. text:function(text){
  165. if(typeoftext!=="object"&&text!=null)
  166. returnthis.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(text));
  167. varret="";
  168. jQuery.each(text||this,function(){
  169. jQuery.each(this.childNodes,function(){
  170. if(this.nodeType!=8)
  171. ret+=this.nodeType!=1?
  172. this.nodeValue:
  173. jQuery.fn.text([this]);
  174. });
  175. });
  176. returnret;
  177. },
  178. wrapAll:function(html){
  179. if(this[0]){
  180. //Theelementstowrapthetargetaround
  181. varwrap=jQuery(html,this[0].ownerDocument).clone();
  182. if(this[0].parentNode)
  183. wrap.insertBefore(this[0]);
  184. wrap.map(function(){
  185. varelem=
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表