我一直在使用 jquery ui 进行开发。今天我被困在图像循环仪上。默认图像滑块代码适用于 3 张图片。我的网站上有 30 张图片,我必须使用 ui-cycler 流畅地循环它,但这是不可能的。为了使它工作,我必须在图像循环器开始发挥作用之前点击静态图片 X 时间。这是 3 个图像的循环器代码:
<script>
$(function() {
// TODO refactor into a widget and get rid of these plugin methods
$.fn.left = function( using ) {
return this.position({
my: "right middle",
at: "left+25 middle",
of: "#container",
collision: "none",
using: using
});
};
$.fn.right = function( using ) {
return this.position({
my: "left middle",
at: "right-25 middle",
of: "#container",
collision: "none",
using: using
});
};
$.fn.center = function( using ) {
return this.position({
my: "center middle",
at: "center middle",
of: "#container",
using: using
});
};
$( "img:eq(0)" ).left();
$( "img:eq(1)" ).center();
$( "img:eq(2)" ).right();
function animate( to ) {
$( this ).stop( true, false ).animate( to );
}
function next( event ) {
event.preventDefault();
$( "img:eq(2)" ).center( animate );
$( "img:eq(1)" ).left( animate )
$( "img:eq(0)" ).right().appendTo( "#container" );
}
function previous( event ) {
event.preventDefault();
$( "img:eq(0)" ).center( animate );
$( "img:eq(1)" ).right( animate );
$( "img:eq(2)" ).left().prependTo( "#container" );
}
$( "#previous" ).click( previous );
$( "#next" ).click( next );
$( "img" ).click(function( event ) {
$( "img" ).index( this ) === 0 ? previous( event ) : next( event );
});
$( window ).resize(function() {
$( "img:eq(0)" ).left( animate );
$( "img:eq(1)" ).center( animate );
$( "img:eq(2)" ).right( animate );
});
});
</script>
这是我的图片参考html:
<div id="container">
<img class = "slide" src="images/slide1.jpg" alt="Race2"/>
<img class="slide" src="images/slide2.jpg" alt="Akshay Kumar"/>
<img class = "slide" src = "images/slide_eng1.jpg" alt = "English Roller"/>
<img class = "slide" src = "images/slide_eng2.jpg" alt = "Bruce Willis"/>
<!-- still many image -->
</div>
我应该怎么做才能让它工作?