index8.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery幻灯片插件Owl Carousel演示-自定义JSON_dowebok</title>
  6. <style>
  7. #owl-demo { width: 900px; margin-left: auto; margin-right: auto;}
  8. #owl-demo .item{ display: block; margin: 5px;}
  9. #owl-demo img { display: block; width: 100%; border: 0 none;}
  10. </style>
  11. <link href="css/owl.carousel.css" rel="stylesheet">
  12. <link href="css/owl.theme.css" rel="stylesheet">
  13. <script src="http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js"></script>
  14. <script src="js/owl.carousel.js"></script>
  15. <script>
  16. $(function(){
  17. $('#owl-demo').owlCarousel({
  18. items: 4,
  19. jsonPath: 'json/customData.json',
  20. jsonSuccess: customDataSuccess
  21. });
  22. function customDataSuccess(data){
  23. var content = '';
  24. for(var i in data['items']){
  25. var img = data['items'][i].img;
  26. var alt = data['items'][i].alt;
  27. var link = data['items'][i].link;
  28. content += '<a class="item" href="' +link+ '"><img src="' +img+ '" alt="' +alt+ '">';
  29. }
  30. $('#owl-demo').html(content);
  31. }
  32. });
  33. </script>
  34. </head>
  35. <body>
  36. <div class="menu">
  37. <p class="menuc">
  38. <span></span>
  39. <a href="./">1、默认</a>
  40. <a href="index2.html">2、单个</a>
  41. <a href="index3.html">3、自动播放</a>
  42. <a href="index4.html">4、显示上一张/下一张</a>
  43. <a href="index5.html">5、自适应高度</a>
  44. <a href="index6.html">6、延迟加载(Lazy Load)</a>
  45. <a href="index7.html">7、加载JSON</a>
  46. <a class="cur" href="index8.html">8、自定义JSON</a>
  47. <a href="index9.html">9、进度条</a>
  48. <a href="index10.html">10、随机显示</a>
  49. </p>
  50. </div>
  51. <div class="main">
  52. <div class="mianc">
  53. <h1>自定义JSON</h1>
  54. <!-- Demo -->
  55. <div id="owl-demo" class="owl-carousel">
  56. </div>
  57. <!-- Demo end -->
  58. <div class="code">
  59. <h3 class="h31 cur">JavaScript</h3>
  60. <div class="pre">
  61. <pre class="pre-show prettyprint linenums">$(function(){
  62. $('#owl-demo').owlCarousel({
  63. items: 4,
  64. jsonPath: 'json/customData.json',
  65. jsonSuccess: customDataSuccess
  66. });
  67. function customDataSuccess(data){
  68. var content = '';
  69. for(var i in data['items']){
  70. var img = data['items'][i].img;
  71. var alt = data['items'][i].alt;
  72. var link = data['items'][i].link;
  73. content += '&lt;a class="item" href="' +link+ '"&gt;&lt;img src="' +img+ '" alt="' +alt+ '"&gt;';
  74. }
  75. $('#owl-demo').html(content);
  76. }
  77. });</pre>
  78. </div>
  79. <h3 class="h32">JSON</h3>
  80. <div class="pre">
  81. <pre class="pre-show prettyprint linenums">{
  82. "items" : [
  83. {
  84. "img": "img/owl1.jpg",
  85. "alt" : "Owl Image 1",
  86. "link" : "http://www.dowebok.com/"
  87. },
  88. {
  89. "img": "img/owl2.jpg",
  90. "alt" : "Owl Image 2",
  91. "link" : "http://www.dowebok.com/93.html"
  92. },
  93. {
  94. "img": "img/owl3.jpg",
  95. "alt" : "Owl Image 3",
  96. "link" : "http://www.dowebok.com/92.html"
  97. },
  98. {
  99. "img": "img/owl4.jpg",
  100. "alt" : "Owl Image 4",
  101. "link" : "http://www.dowebok.com/91.html"
  102. },
  103. {
  104. "img": "img/owl5.jpg",
  105. "alt" : "Owl Image 5",
  106. "link" : "http://www.dowebok.com/90.html"
  107. },
  108. {
  109. "img": "img/owl6.jpg",
  110. "alt" : "Owl Image 6",
  111. "link" : "http://www.dowebok.com/89.html"
  112. },
  113. {
  114. "img": "img/owl7.jpg",
  115. "alt" : "Owl Image 7",
  116. "link" : "http://www.dowebok.com/88.html"
  117. },
  118. {
  119. "img": "img/owl8.jpg",
  120. "alt" : "Owl Image 8",
  121. "link" : "http://www.dowebok.com/87.html"
  122. }
  123. ]
  124. }</pre>
  125. </div>
  126. <h3 class="h33">HTML</h3>
  127. <div class="pre">
  128. <pre class="pre-show prettyprint linenums">&lt;div id="owl-demo" class="owl-carousel"&gt;
  129. &lt;/div&gt;</pre>
  130. </div>
  131. <h3 class="h34">CSS</h3>
  132. <div class="pre">
  133. <pre class="pre-show prettyprint linenums">#owl-demo {
  134. width: 900px;
  135. margin-left: auto;
  136. margin-right: auto;
  137. }
  138. #owl-demo .item {
  139. display: block;
  140. margin: 5px;
  141. }
  142. #owl-demo img {
  143. display: block;
  144. width: 100%;
  145. border: 0 none;
  146. }</pre>
  147. </div>
  148. </div>
  149. <p class="vad">
  150. <a href="http://www.dowebok.com/" target="_blank">dowebok.com</a>
  151. <a href="http://www.dowebok.com/93.html" target="_blank">说 明</a>
  152. <a href="http://www.dowebok.com/93.html" target="_blank">下 载</a>
  153. </p>
  154. </div>
  155. </div>
  156. <!-- 以下是统计及其他信息,与演示无关,不必理会 -->
  157. <style>
  158. * { margin: 0; padding: 0;}
  159. html, body { height: 100%; overflow: hidden;}
  160. body { font-family: Consolas,arial,"宋体";}
  161. .menu { position: absolute; left: 0; top: 0; width: 200px; height: 100%; background-color: #ccc; font-family: Consolas,arial,"宋体";}
  162. .menuc { height: 100%; overflow-x: hidden; overflow-y: auto;}
  163. .menu span { display: block; height: 100px;}
  164. .menu a { display: block; height: 40px; margin: 0 0 1px 2px; padding-left: 10px; line-height: 40px; font-size: 14px; color: #333; text-decoration: none;}
  165. .menu a:hover { background-color: #eee;}
  166. .menu .cur { color: #000; background-color: #fff !important;}
  167. .main { height: 100%; margin-left: 200px;}
  168. .mianc { position: relative; height: 100%; overflow-x: hidden; overflow-y: auto;}
  169. .main h1 { width: 900px; margin: 40px auto; font: 32px "Microsoft Yahei";}
  170. .explain, .dowebok-explain { margin-top: 20px; font-size: 14px; text-align: center; color: #f50;}
  171. .vad { margin: 50px 0 10px; font-family: Consolas,arial,宋体,sans-serif; text-align:center;}
  172. .vad a { display: inline-block; height: 36px; line-height: 36px; margin: 0 5px; padding: 0 50px; font-size: 14px; text-align:center; color:#eee; text-decoration: none; background-color: #222;}
  173. .vad a:hover { color: #fff; background-color: #000;}
  174. .thead { width: 728px; height: 90px; margin: 0 auto; border-bottom: 40px solid transparent;}
  175. .code { position: relative; margin-top: 100px; padding-top: 41px;}
  176. .code h3 { position: absolute; top: 0; z-index: 10; width: 100px; height: 40px; font: 16px/40px "Microsoft Yahei"; text-align: center; cursor: pointer;}
  177. .code .cur { border: 1px solid #f0f0f0; border-bottom: 1px solid #f8f8f8; background-color: #f8f8f8;}
  178. .code .h31 { left: 0;}
  179. .code .h32 { left: 102px;}
  180. .code .h33 { left: 204px;}
  181. .code .h34 { left: 306px;}
  182. .code { width: 900px; margin-left: auto; margin-right: auto;}
  183. pre { padding: 15px 0; border: 1px solid #f0f0f0; background-color: #f8f8f8;}
  184. .f-dn { display: none;}
  185. </style>
  186. <link href="http://xww-global.u.qiniudn.com/prettify.css" rel="stylesheet">
  187. <script src="http://xww-global.u.qiniudn.com/prettify.js"></script>
  188. <script>
  189. window.prettyPrint && prettyPrint();
  190. $('.code h3').not(':first').next().addClass('f-dn');
  191. $('.code h3').click(function(){
  192. $(this).addClass('cur').siblings('h3').removeClass('cur');
  193. $(this).next().removeClass('f-dn').siblings('.pre').addClass('f-dn');
  194. });
  195. </script>
  196. </body>
  197. </html>