(function($) {
$.fn. function(options) {
var ops = $.extend({}, $.fn.scrollWait.defaults, options);
var opts = $.meta ? $.extend({}, ops, $( this).data()) : ops;
/**
* 顯示位置
*/
var win = $(window);
var winheight = win.height();
var winwidth = win.width();
var dsize = opts.size;
var top = opts.top;
var left = opts.left;
var dtop = !top && top != "" && typeof top != "undefined" && top != 0
? (winheight - dsize) / 2
: top;
var dleft = !left && left != "" && typeof left ! undefined"
&& left != 0 ? (winwidth - dsize) / 2 : left;
// 原點數量
var num = opts.num;
// 原點直徑
var Rvar. = dsize / num * opts.areaWeight;
// 半徑
var r = 1 / 2 * R;
// 外側圓直徑
var outerR = 1 / 2 * dsize;
var innerR = outerR - R;
// 遍歷新增原點物件
for (var i = 0; i $('body') .append($(" i "">
"));
}
// 其實座標0,0
var i = 0;
var innerArray = new Array(num);
/**
* 計算內圓上點的中心座標
*/
for (var j = 0; j var x, y;
var ang = i * 360 / num;
if (0 x = outerR * Math.sin(ang / 180 * Math. PI) outerR;
y = outerR - outerR * Math.cos(ang / 180 * Math.PI);
}
if (90 x =if = outerR * Math.cos((ang - 90) / 180 * Math.PI) outerR;
y = outerR * Math.sin((ang - 90) / 180 * Math.PI) outerR;
}
if (180 x = outerR - outerR * Math.sin((ang - 180) / 180 * Math.PI);
y = outerR * Math.cos ((ang - 180) / 180 * Math.PI) outerR;
}
if (270 x = outerR - outerR * Math.cos((ang - 270) / 180 * Math.PI);
y = outerR - outerR * Math.sin((ang - 270) / 180 * Math.PI);
}
innerArray[j] = new Array (dtop y - r, dleft x - r);
i ;
}
/**
* 畫圓
*/
$(".innerCircle").each(function() {
$(this).css({
'width' : R "px",
'height' : R "px",
'border-top-left-radius' : r "px ",
'border-top-right-radius' : r "px",
'border-bottom-left-radius' : r "px",
'border-bottom-right-radius' : r "px"
});
});
for (var i = 0; i $("#innerCircle" i).css({
'top' : innerArray[i][0] "px",
'left' : innerArray[i][1] "px"
});
}
// 查找目前暫停的圓的位置
var val = $("#current").val();
if (val == undefined || val == "") {
$("body" ).append($(""));
k = 0;
} else {
k = val;
}
var o = new Object();
var timer;
// 開始旋轉
o.start = function() {
var first;
var g = $("#grade ").val();
if (g == undefined || g == "") {
$("body").append($(""));
first = 1;
} else {
first = g;
}
timer = setInterval(function() {
if (first % 2 == 1) {
$("#innerCircle" k).removeClass("innerCircle")
.addClass("innerCircle-change");
}
if (first % 2 ==");
}
if (first % 2 === 0) {
$("#innerCircle" k).removeClass("innerCircle-change")
.addClass("innerCircle");
}
if (k == (num - 1 )) {
k = 0;
console.log(first);
first ;
$("#grade").val(first);
} else {
k ;
}
// 覆蓋值
$("#current").val(k);
}, opts.speed);
return this;
}
// 暫停
o.stop = function() {
clearInterval(timer);
return this;
}
// 結束
o.end = function() {
clearInterval(timer);
// 移除所有元素
$(".innerCircle,.innerCircle-change,#current,#grade").remove();
}
return o;
}
$.fn.scrollWait.defaults = {
size : 80,
top : null,
left : null,
// 數量
num : 8,
speed : 200,
// 圓點佔整個面積的比重
areaWeight : 5 / 4
};
})(jQuery);