相信列位初學寫小法式的新手們,都需要一些案例來仿照進修。今天給大師供給一個輪播結果的實現方式,供大師參考。
<script src="jquery-3.0.0.js"></script>
<script type="text/javascript">
var timer;
$(function() {
//設置圖片標的目的左移
imgshow();
//點擊暫停按鈕事務
$(".pause").click(function () {
clearInterval(timer);
});
//點擊播放按鈕事務
$(".play").click(function () {
imgshow();
});
//點擊左按鈕
$(".prev").click(function () {
imganimation("left");
});
//點擊右按鈕
$(".next").click(function () {
imganimation("right");
});
function imganimation(res) {
//圖片標的目的左走的輪播
if(res=="right"){
//animate()動畫第一個li標的目的左移動20%
$(".lilist:first").animate({
"marginLeft": "-20%"
}, 700, "linear", function () {
//這個li回到本來的位置
$(this).css("marginLeft", "0px");
//將它追加到ul的最后的位置
$(this).appendTo($(".ullist"));
});
//設置小框的圖片輪播,道理與年夜框圖片輪播一致
$(".s_lilist:first").animate({
"marginLeft": "-20%"
}, 650, "linear", function () {
$(this).css("marginLeft", "0px");
$(this).appendTo($(".s_ullist"));
});
//圖片標的目的右走,與標的目的左的道理不異
$(".lilist:first").animate({
"marginLeft": "20%"
}, 700, "linear", function () {
$(this).css("marginLeft", "0px");
$(".lilist:last").prependTo($(".ullist"));
});
$(".s_lilist:first").animate({
"marginLeft": "20%"
}, 650, "linear", function () {
$(this).css("marginLeft", "0px");
$(".s_lilist:last").prependTo($(".s_ullist"));
});
};
};
//默認圖片主動標的目的左走
function imgshow() {
timer = setInterval(function (){
imganimation("right");
} , 2000);
};
});
</script>
最后,附上css樣式與html樣式。
0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!