<script src="/js/jquery.min.js" type="text/javascript"></script> <script type="text/javascript" src="/js/jquery.cycle2.min.js"></script>
<div id="content-ob" class="cycle-slideshow" data-cycle-fx="scrollHorz" data-cycle-timeout="10000" data-cycle-speed="1000" data-cycle-slides="a" data-cycle-pager=".custom-pager" data-cycle-pager-template=" <a href=# class='custom-pager-button'> </a>" > <a href="/page1.html"><img src="/img/pic1.jpg" /></a> <a href="/page2.html"><img src="/img/pic2.jpg" /></a> <a href="/page3.html"><img src="/img/pic3.jpg" /></a> <a href="/page4.html"><img src="/img/pic4.jpg" /></a> <a href="/page5.html"><img src="/img/pic5.jpg" /></a> <div id="progress"></div> <div class="custom-pager"></div> </div>
class= "cycle-slideshow"
is responsible for converting our block into scrolling banner. This attribute is important; if present, the Cycle2 library converts a block. data-cycle-fx= "scrollHorz"
- specify the method of turning the banners horizontally. data-cycle-timeout= "10000"
- time of displaying each banner in milliseconds, i.e. we have 10 seconds to display the banner. data-cycle-speed= "1000"
- time to animate banner turning, 1 second. data-cycle-slides= "a"
- this attribute indicates which nested tag contains the scrolling blocks. Since we leaf through the blocks <a href= "/pageX.html"><img src= "/img/picX.jpg" /></a>
then the tag is a. data-cycle-pager= ".custom-pager"
- selector for the block of navigation buttons. We use a non-standard block, because The standard unit does not suit us by design. data-cycle-pager-template= " <a href=# class='custom-pager-button'> </a>"
- navigation button template. <a href="/page1.html"><img src="/img/pic1.jpg" /></a> <a href="/page2.html"><img src="/img/pic2.jpg" /></a> ...
<div id= "progress" ></div>
- a block for drawing a progress bar. <div class= "custom-pager" ></div>
- block for drawing navigation buttons. .custom-pager{ /* */ margin-left:435px; margin-top:5px; overflow:hidden; } a.custom-pager-button{ /* */ display:block; float:left; margin-right:5px; width:29px; height:13px; overflow:hidden; background-image:url(/img/newdis/ob-in.png); background-position:left top; background-repeat:no-repeat; cursor: pointer; } .custom-pager a.cycle-pager-active{ /* */ background-image:url(/img/newdis/ob.png) !important; cursor: pointer; } .custom-pager > * { cursor: pointer;} /* - */ #progress { /* */ margin-top:3px; height: 3px; width: 0px; background: #860b70; z-index: 500; }
var progress = $('#progress'), slideshow = $( '.cycle-slideshow' ); /* - */ slideshow.on( 'cycle-initialized cycle-before', function( e, opts ) { if(opts.slideNum==undefined) number=1; /* undefined, */ else number=opts.slideNum; number--; w=Math.round(100*number/opts.slideCount); /* % */ progress.stop(true).css( 'width', w+'%' ); /* */ }); /* - */ slideshow.on( 'cycle-initialized cycle-after', function( e, opts ) { if(opts.slideNum==undefined) number=1;/* undefined, */ else number=opts.slideNum; w=Math.round(100*number/opts.slideCount); /* % */ if(w>100) w=100; // /* % */ progress.animate({ width: w+'%' }, opts.timeout, 'linear' ); });
Source: https://habr.com/ru/post/269351/
All Articles