Javascript Socket.io和jQuery-合并
我有以下代码:Javascript Socket.io和jQuery-合并,javascript,jquery,node.js,socket.io,Javascript,Jquery,Node.js,Socket.io,我有以下代码: <!DOCTYPE html> <html> <head> <title>jQuery Knob demo</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="js/jqu
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
connectionCounter.js
var express = require("express");
var app = express();
var socket = require("socket.io");
var server = app.listen(4000);
var io = socket.listen(server);
app.get('/', function(request, response){
response.sendfile(__dirname + "/index.html");
});
var activeClients = 0;
io.sockets.on('connection', function(socket){clientConnect(socket)});
function clientConnect(socket){
activeClients +=1;
io.sockets.emit('message', {clients:activeClients});
socket.on('disconnect', function(){clientDisconnect()});
}
function clientDisconnect(){
activeClients -=1;
io.sockets.emit('message', {clients:activeClients});
}
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
index.html(计算连接到网站的客户端数)
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
连接计数器
函数msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(文档).ready(函数(){
$clientCounter=$(“#客户端计数”)
var socket=io.connect('http://localhost:4000');
on('message',function(msg){msgReceived(msg)});
});
0个已连接的客户端
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
和index.html(jQuery旋钮)
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
jQuery旋钮演示
$(函数($){
$(“.knob”).knob({
更改:功能(值){
//console.log(“更改:+值);
},
释放:功能(值){
//log(this.$.attr('value'));
控制台日志(“释放:+值);
},
取消:函数(){
console.log(“cancel:,this”);
},
绘图:函数(){
//“特隆”案
如果(此.$.data('skin')=='tron'){
var a=this.angle(this.cv)//角度
,sa=this.startAngle//上一个起始角度
,sat=this.startAngle//起始角度
,ea//上一个端角
,eat=sat+a//端角
,r=1;
this.g.lineWidth=this.lineWidth;
这个光标
&&(sat=eat-0.3)
&&(eat=eat+0.3);
如果(此.o.displayPrevious){
ea=此星形缠结+此角度(此.v);
这个光标
&&(sa=ea-0.3)
&&(ea=ea+0.3);
这是g.beginPath();
this.g.strokeStyle=this.p颜色;
this.g.arc(this.xy,this.xy,this.radius-this.lineWidth,sa,ea,false);
这是笔划();
}
这是g.beginPath();
this.g.strokeStyle=r?this.o.fgColor:this.fgColor;
this.g.arc(this.xy,this.xy,this.radius-this.lineWidth,sat,eat,false);
这是笔划();
这个g.lineWidth=2;
这是g.beginPath();
this.g.strokeStyle=this.o.fgColor;
this.g.arc(this.xy,this.xy,this.radius-this.lineWidth+1+this.lineWidth*2/3,0,2*Math.PI,false);
这是笔划();
返回false;
}
}
});
//无限旋钮、iPod点击轮示例
变量v,向上=0,向下=0,i=0
,$idir=$(“div.idir”)
,$ival=$(“div.ival”)
,incr=function(){i++;$idir.show().html(“+”.fadeOut();$ival.html(i);}
,decr=function(){i--;$idir.show().html(“-”.fadeOut();$ival.html(i);};
$(“input.infinite”).旋钮(
{
最低:0
,最多20
,stopper:false
,更改:函数(){
如果(v>this.cv){
如果(向上){
decr();
up=0;
}else{up=1;down=0;}
}否则{
if(vp{font size:20px}
×;大
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
数据宽度=“700”
我曾尝试将这两个index.html组合在一起,但没有成功。单独工作,但当我组合并尝试运行nodejs时,计数器不工作,旋钮也不显示
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
有什么建议吗
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
如何:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
jQuery旋钮:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
合并:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function msgReceived(msg){
$clientCounter.html(msg.clients);
}
$(document).ready(function () {
$clientCounter = $("#client_count")
var socket = io.connect('http://localhost:4000');
socket.on('message', function(msg){msgReceived(msg)});
});
$(function($) {
$(".knob").knob({
change : function (value) {
//console.log("change : " + value);
},
release : function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
draw : function () {
// "tron" case
if(this.$.data('skin') == 'tron') {
var a = this.angle(this.cv) // Angle
, sa = this.startAngle // Previous start angle
, sat = this.startAngle // Start angle
, ea // Previous end angle
, eat = sat + a // End angle
, r = 1;
this.g.lineWidth = this.lineWidth;
this.o.cursor
&& (sat = eat - 0.3)
&& (eat = eat + 0.3);
if (this.o.displayPrevious) {
ea = this.startAngle + this.angle(this.v);
this.o.cursor
&& (sa = ea - 0.3)
&& (ea = ea + 0.3);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up=0,down=0,i=0
,$idir = $("div.idir")
,$ival = $("div.ival")
,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
$("input.infinite").knob(
{
min : 0
, max : 20
, stopper : false
, change : function () {
if(v > this.cv){
if(up){
decr();
up=0;
}else{up=1;down=0;}
} else {
if(v < this.cv){
if(down){
incr();
down=0;
}else{down=1;up=0;}
}
}
v = this.cv;
}
});
});
</script>
<style>
body{
padding: 0;
margin: 0px 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 300;
text-rendering: optimizelegibility;
}
p{font-size: 30px; line-height: 30px}
div.demo{text-align: center; width: 280px; float: left}
div.demo > p{font-size: 20px}
</style>
</head>
<body>
<p><span id="client_count">0</span> connected clients</p>
<div style="clear:both"></div>
<div id="big" class="demo" style="height:800px;width:100%">
<p>× Big !</p>
<pre>
data-width="700"
</pre>
<input class="knob" data-min="0" data-max="100" data-width="700" data-height="700" data-thickness=".7" data-cursor=true>
</div>
</body>
</html>
jQuery旋钮演示
函数msgReceived(msg){
$clientCounter.html(msg.clients);