ã¹ã©ã¤ãã¼ãå®è£ ããããã®ã©ã¤ãã©ãªã«ã¯æ§ã ãªãã®ãããã¾ãããä»åã¯ãç°¡åã«ã¬ã¹ãã³ã·ã表示ã®ã§ãã人æ°ã®ãã©ã°ã¤ã³ãslickãã使ã£ãã¹ã©ã¤ãã¼ã®å®è£ ããç´¹ä»ãã¾ãã
ã¾ãã¯ä»¥ä¸ã®URLã¸è¡ãããget it nowãâãDownload Nowããã¯ãªãã¯ãã¦ãslickããã¼ã«ã«ã«ãã¦ã³ãã¼ããã¦ããã¾ãã(cdnã§ãå¯)
https : //kenwheeler.github.io/slick/
ãã¦ã³ãã¼ããããã©ã«ãã¼ãããslickãã¨ããååã®ãã©ã«ããã表示ããããhtmlãã¡ã¤ã«ãå ¥ã£ããã©ã«ãã«ç§»åããã¾ãã
次ã«htmlãã¡ã¤ã«ãå¤æ´ãã¦ããã¾ãã
<html> <head> <title>Responsive Slider</title> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="slick/slick.css"/> <link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/> </head> <body> <section class="next slider"> <div><img src="img/sample1.png"></div>ã <div><img src="img/sample2.png"></div>ã <div><img src="img/sample3.png"></div>ã <div><img src="img/sample4.png"></div>ã <div><img src="img/sample5.png"></div>ã <div><img src="img/sample6.png"></div>ã </section> <script src="https : //code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script> <script type="text/javascript" src="slick/slick.min.js"></script> </body> </html> <style> html, body { margin : 0; padding : 0; } * { box-sizing : border-box; } .slider { width : 50%; margin : 100px auto; } .slick-slide { margin : 0px 20px; height : auto; } .slick-slide img { width : 100%; } .slick-prev : before, .slick-next : before { color : black; } .slick-slide { transition : all ease-in-out .3s; opacity : .2; } .slick-active { opacity : .5; } .slick-current { opacity : 1; } </style>
ããã§slickã®è¨å®ã¯å®äºã§ãããããã¼ã®ä¸ã§ãå ã»ã©ãã¦ã³ãã¼ãããslickãã©ã«ãã®ä¸ã®CSSã³ã¼ãã¨ãªã³ã¯ãããbodyã¿ã°ã®ç´åã§ãjQueryãèªã¿è¾¼ã¿ãJSã³ã¼ãã¨ãªã³ã¯ããã¦ãã¾ãã
ã¹ã©ã¤ãã¼ã«ç»åã使ãå ´åã¯imgã¿ã°ã並ã¹ããã®ä»ã®å ´åã¯divã¿ã°ãªã©ã並ã¹ãä»»æã®ã¯ã©ã¹ãæå®ããç®±ãä½ãã¾ãã(sectionã§ãªãã¦ãæ§ãã¾ãã)
styleã¿ã°ã§å²ãã CSSã³ã¼ãã¯ãªãã¦ãæ§ãã¾ããããã¹ã©ã¤ãã¼ã«æå®ããç»åãµã¤ãºã«ãã£ã¦ã¯ãã¬ã¹ãã³ã·ãã®è¡¨ç¤ºãå´©ãããã¨ãããã®ã§ã
.slick-slide { height : auto; }
ã¯è¨å®ãã¦ããã¾ãããã
次ã«ãå®éã«slickã使ã£ã¦ã¹ã©ã¤ãã¼ã表示ãããããã«ãbodyã¿ã°ã®ç´åã«æ¬¡ã®jsã³ã¼ããæ¿å ¥ãã¾ãã
<script type="text/javascript"> $(document).on('ready', function() { $('.next').slick({ slidesToShow : 1, slidesToScroll : 1, dots : true, centerMode : true, focusOnSelect : true }); }); </script>
ã¹ã©ã¤ãã¼ã«ä½¿ç¨ããç»åãå ¥ã£ãã¿ã°ã«æå®ããã¯ã©ã¹å(ããã§ã¯next)ãJSå ã§å¼ã³åºããã¹ã©ã¤ãã¼ã®è¡¨ç¤ºã«é¢ããè¨å®ããã¦ãã¾ãã
ã¾ããã¹ã©ã¤ãã¼ã®ä¸»ãªè¨å®é ç®ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã
dots : true/false | ãããã®ããã表示/é表示 |
---|---|
slidesToShow : 1 | 表示ã¹ã©ã¤ãæ° |
autoplay : true/false | ã¹ã©ã¤ãã®èªååç |
autoplaySpeed : 2000 | èªååçã®éã(ms) |
arrows : true/false | ç¢å°ã®ããã表示/é表示 |
speed : 300 | ã¹ã©ã¤ãã®éã(ms) |
infinite : true/false | æå¾ã®ã¹ã©ã¤ãã®æ¬¡ã«æåã®ã¹ã©ã¤ãã表示ãã/æå¾ã®ã¹ã©ã¤ãã¼ã§ã¹ã©ã¤ããæ¢ãã |
fade : true/false | ã¹ã©ã¤ãã®ãã§ã¼ã表示 |
centerMode : true/false | åå¾ã®ã¹ã©ã¤ãã®è¡¨ç¤º |
å ã»ã©ã®JSã³ã¼ãã§ä½æããã¹ã©ã¤ãã¼ã¯æ¬¡ã®ãããªãã®ã«ãªãã¾ãã
ã¾ãããã®JSã³ã¼ããæ¹å¤ããã ãã§ãæ§ã
ãªã¹ã©ã¤ãã¼ãä½æãããã¨ãå¯è½ã«ãªãã¾ãã
ããã¤ãããµã³ãã«ããç´¹ä»ãã¦ããã¾ãã
ãµã³ãã«1(autoplay)
JSã³ã¼ã
<script type="text/javascript"> $(document).on('ready', function() { $('.autoplay').slick({ slidesToShow : 3, slidesToScroll : 1, autoplay : true, autoplaySpeed : 2000, }); }); </script>
ãµã³ãã«2(slider-for & nav)
JSã³ã¼ã
<script type="text/javascript"> $(document).on('ready', function() { $('.slider-for').slick({ slidesToShow : 1, slidesToScroll : 1, arrows : false, fade : true, asNavFor : '.slider-nav' }); $('.slider-nav').slick({ slidesToShow : 3, slidesToScroll : 1, asNavFor : '.slider-for', dots : true, centerMode : true, focusOnSelect : true }); }); </script>
ãµã³ãã«3(one-time)
JSã³ã¼ã
<script type="text/javascript"> $(document).on('ready', function() { $('.one-time').slick({ dots : true, infinite : true, speed : 300, slidesToShow : 1, adaptiveHeight : true }); }); </script>
ãµã³ãã«4(fade)
JSã³ã¼ã
<script type="text/javascript"> $(document).on('ready', function() { $('.fade').slick({ dots : true, infinite : true, speed : 500, fade : true, cssEase : 'linear' }); }); </script>
ãµã³ãã«5(vertical-center)
JSã³ã¼ã
<script type="text/javascript"> $(document).on('ready', function() { $(".vertical-center").slick({ dots : true, vertical : true, centerMode : true, }); }); </script>
ãã²ãããã®ãµã³ãã«ãåèã«ãã¤ã¤ããµã¤ãã«ãã£ãã¹ã©ã¤ãã¼ãä½ã£ã¦ã¿ã¦ãã ããã