我第一次摸索 jquery 插件使自己摆脱了 DOM 对象操作。我已经阅读了很多关于插件的内容,这让我的大脑受伤了。虽然我已经得到了插件来做预期的事情。我无法相信我设置变量和初始化的方式是正确的。虽然不需要解决所有可能发生的问题,但如果您能评论更多不合规的方面,以便将来的插件可以在一定程度上得到解决,我将不胜感激。示例 http://www.wordscans.com/jtest/(忽略外环)
编码..
enter code here
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD>
<script type=text/javascript src="jquery.min.js"></script>
<script type=text/javascript src='RkJQRotate.js'></script>
<script type=text/javascript>
function kickoff() {makeins(); ringpos();
setTimeout('$("").rotateinner()',200); $('#ovobj').rotoval();}
function makeins() {
jQuery('<div></div>',{'id': 'tmplx','lft':'-90','top':0, 'ang':0}).addClass ('incirc').appendTo('body');
for(var i=0; i<4; i++) {idrf='incir'+i; var img='pic/rot'+i+'.gif';
$('#tmplx').clone().attr('id',idrf).css({'background-image':'url("'+img+'")'}).appendTo('body');}
$('#ovalob').clone().attr('id','ovobj').appendTo('body').fadeIn(40);
$('#ovobj').css({left:'50px',top:'50px','display':'block'}).fadeIn(40);}
function ringpos() {var coord=$('#ringhold').offset(); VposX=coord.left; VposY=coord.top;
var inca=360/Velnum; Vstang=Vstang%360; var sang=Vstang; var rad=Vdiam/2; var offs=((Vringw-Vwdh)/2);
for(var i=0; i<4; i++) {var erf='#incir'+i; var quadr=Math.floor(sang/90); var cang=sang%90;
var ang=cang*(Math.PI/180); sang+=inca;/*radians*/
var x=rad*Math.cos(ang); var y=rad * Math.sin(ang); xx=(quadr%2)?x:y; yy=(quadr%2)?y:x;
xx=(quadr>1)?-xx:xx; yy=(quadr%3)?yy:-yy; erf='#incir'+i; rlt=VposX+xx+offs; rtp=VposY+yy+offs;
$(erf).css({left:rlt+'px',top:rtp+'px','display':'block'}).fadeIn(40);} }
var Vdiam=152; var Velnum=4; Vwdh=98; Vht=98; Velm='ringhold'; Vstang=45; Vringw=300; Vinc=-2.001; var VposX; var VposY;
(function($) {
var inca=360/Velnum; inca=(Vinc<0)?-inca:inca; var rad=Vdiam/2; var offs=((Vringw-Vwdh)/2);
var trig=1; var trigovl=1; var intval=null; var intvalo=null;
//rotateinner=function ()
$.fn.rotateinner=function () {/* return setInterval(function() Dont try chaining* with return*/
if(trig==0) { clearInterval(intval); return}
intval=setInterval(function() {var v=Vstang+Vinc; Vstang=(v>360)?v%360:(v<0)?360+v:v; var sang=Vstang;
for(var i=0; i<4; i++) {var erf='#incir'+i; var quadr=Math.floor(sang/90); var cang=sang%90;
var ang=cang*(Math.PI/180); v=sang+inca; sang=(v>360)?v%360:(v<0)?360+v:v;; /*radians*/
var x=rad*Math.cos(ang); var y=rad * Math.sin(ang); xx=(quadr%2)?x:y; yy=(quadr%2)?y:x;
xx=(quadr>1)?-xx:xx; yy=(quadr%3)?yy:-yy; erf='#incir'+i; rlt=VposX+xx+offs; rtp=VposY+yy+offs;
$(erf).css({left:rlt+'px',top:rtp+'px'}); }; }, 85); }
var lgrad=230; var smrad=120; var stang=45; var oincr=2.2; var low=280;
$.fn.rotoval=function() {
if(trigovl==0) { clearInterval(intvalo); return}
jqobj='#'+this.attr('id');
intvalo=setInterval(function() {
if($(jqobj).attr('oang')==undefined) {$(jqobj).attr('oang',stang);}
oang=$(jqobj).attr('oang');
var quadr=Math.floor((oang)/90); var rnang=(oang%90); rnang=(rnang)?rnang:0.01;
if(quadr%2){rnang=90-rnang;} var rnang=rnang*(Math.PI/180);
var frma=lgrad*smrad; var frmb=Math.pow(smrad*Math.sin(rnang),2);
var frmc=Math.pow(lgrad*Math.cos(rnang),2)
var radfac=frma/Math.sqrt(frmb+frmc);
var x=radfac*Math.sin(rnang);var y=radfac*Math.cos(rnang);
xx=(quadr<2)?x:-x; yy=(quadr%3)?y:-y;
rlt=VposX/1+xx/1+offs; rtp=VposY/1+yy/1+offs+low;
$(jqobj).css({'left':rlt+'px','top':rtp+'px'});
var v=oang/1+oincr+0.001; oang=(v>360)?v%360:(v<0)?360+v:v;
$(jqobj).attr('oang',oang);}, 80); }
})(jQuery);
<style>
.incirc {display:none;position:absolute;width:98px;height:98px;z-index:20}
</style>
</head>
<body onload=setTimeout('kickoff()',100);>
<div id='ringhold'><div id='ringbs'></div><div id='ringtp'></div><div id='ovalob' class='ovalob''></div></div>
</body></HTML>
感谢您对此提供的任何可能的帮助,并感谢所有花时间为本网站提供帮助的人,作为出现问题时的第一站。