0
我有一個用於幻燈片放映的以下腳本的問題。目前它是靜態的,我打算包含setInterval,這樣幻燈片就會旋轉。任何人都可以建議一些關於如何更好地實現這個方法的東西,因爲我無法找到設置setInterval的適當位置。幻燈片中的setInterval
下面是代碼:
<script type="text/javascript">
$(document).ready(function() {
var theImage = $('ul.photos li img');
var theWidth = theImage.width()
//wrap into mother div
$('ul.photos').wrap('<div id="mother" />');
//assign height width and overflow hidden to mother
$('#mother').css({
width: function() {
return theWidth;
},
height: function() {
return theImage.height();
},
position: 'relative',
overflow: 'hidden'
});
//get total of image sizes and set as width for ul
var totalWidth = theImage.length * theWidth;
$('ul.photos').css({
width: function(){
return totalWidth;
}
});
$(theImage).each(
function(intIndex){
$(this).nextAll('a')
.bind("click", function(){
if($(this).is(".next")) {
$(this).parent('li').parent('ul').animate({
"margin-left": (-(intIndex + 1) * theWidth)
}, 1000)
} else if($(this).is(".previous")){
$(this).parent('li').parent('ul').animate({
"margin-left": (-(intIndex - 1) * theWidth)
}, 1000)
} else if($(this).is(".startover")){
$(this).parent('li').parent('ul').animate({
"margin-left": (0)
}, 1000)
}
});//close .bind()
});//close .each()
});
</script>
我將是任何答案非常感激。
嗨之間引入延遲!感謝你的回答。 嗯,我不知道什麼函數的名稱,因爲沒有定義的整個腳本停止工作。我對JavaScript和jQuery不太瞭解,所以我可能會搞砸了。不過,你如何期望得到的代碼看起來像? – Dronich