Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a round menu with javascript?
    primarykey
    data
    text
    <p>1:I want to make a round menu with javascript in which items could response to click and gesturechange events.The effects are: a):If the selected item is not frontest,then it will circle to the frontest position after being clicked; b):If the gesture change is down or right,all the items will circle clockwise by some degrees;otherwise they will circle anti-clockwise by some degrees</p> <p>2:I have got an example,but i did't firgure out how it works.Could you guys give me some advice or make some comments to the code ? The example is below:</p> <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;style&gt; #show{position:relative;margin:20px auto;width:800px;border:1px solid #999999;} .item{position:absolute;height:40px;width:60px;background:#999999;border:1px solid #eeeeee;cursor:pointer;} &lt;/style&gt; &lt;script&gt; var len; var showerObj; var listObj; var showerWidth=800; var showerHeight=400; var r; var cR=0; var ccR=0; var timer=0; window.onload=function(){ showerObj=document.getElementById("show"); listObj=showerObj.getElementsByTagName("div"); len=listObj.length; r=Math.PI/180*360/len; for(var i=0;i&lt;len;i++){ var item=listObj[i]; item.style.top=showerHeight/2+Math.sin(r*i)*showerWidth/2-20+"px"; item.style.left=showerWidth/2+Math.cos(r*i)*showerWidth/2-30+"px"; item.rotate=(r*i+2*Math.PI)%(2*Math.PI); item.onclick=function(){ cR=Math.PI/2-this.rotate; timer || (timer=setInterval(rotate,10)); } } var rX=showerObj.offsetLeft+showerWidth/2; var ry=showerObj.offsetTop+showerHeight/2; var rotate=function(){ ccR=(ccR+2*Math.PI)%(2*Math.PI); if(cR-ccR&lt;0) cR=cR+2*Math.PI; if(cR-ccR&lt;Math.PI){ ccR=ccR+(cR-ccR)/19; }else{ ccR=ccR-(2*Math.PI+ccR-cR)/19; } if(Math.abs((cR+2*Math.PI)%(2*Math.PI)-(ccR+2*Math.PI)%(2*Math.PI))&lt;Math.PI/720){ ccR=cR; clearInterval(timer); timer=0; } for(var i=0;i&lt;len;i++){ var item=listObj[i]; var w,h; var sinR=Math.sin(r*i+ccR); var cosR=Math.cos(r*i+ccR); w=60+0.6*60*sinR; h=(40+0.6*40*sinR); item.style.cssText +=";width:"+w+"px;height:"+h+"px;top:"+parseInt(showerHeight/2+sinR*showerWidth/2/3-w/2)+"px;left:"+parseInt(showerWidth/2+cosR*showerWidth/2-h/2)+"px;z-index:"+parseInt(showerHeight/2+sinR*showerWidth/2/3-w/2)+";"; } } document.getElementById("l").onclick=function(){ cR=(cR+r+2*Math.PI)%(2*Math.PI); timer || (timer=setInterval(rotate,10)); } document.getElementById("r").onclick=function(){ cR=(cR-r+2*Math.PI)%(2*Math.PI); timer || (timer=setInterval(rotate,10)); } rotate(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input id="l" type="button" value="left" &gt; &lt;input id="r" type="button" value="right" &gt; &lt;div id="show"&gt; &lt;div class="item"&gt;1&lt;/div&gt; &lt;div class="item"&gt;2&lt;/div&gt; &lt;div class="item"&gt;3&lt;/div&gt; &lt;div class="item"&gt;4&lt;/div&gt; &lt;div class="item"&gt;5&lt;/div&gt; &lt;div class="item"&gt;6&lt;/div&gt; &lt;div class="item"&gt;7&lt;/div&gt; &lt;div class="item"&gt;8&lt;/div&gt; &lt;div class="item"&gt;9&lt;/div&gt; &lt;div class="item"&gt;0&lt;/div&gt; &lt;div class="item"&gt;a&lt;/div&gt; &lt;div class="item"&gt;b&lt;/div&gt; &lt;div class="item"&gt;1&lt;/div&gt; &lt;div class="item"&gt;2&lt;/div&gt; &lt;div class="item"&gt;3&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>JSFiddle <a href="http://jsfiddle.net/vCpHz/" rel="nofollow">here</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload