jQuery汽车车速表效果js代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 jQuery汽车车速表效果js代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

jQuery汽车车速表效果js代码

HTML代码(index.html):

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery汽车车速表效果</title>
    <script src="jquery-1.4.min.js"></script>
    <script src="jquery.speedometer.js"></script>
    <script src="jquery.jqcanvas-modified.js"></script>
    <script src="excanvas-modified.js"></script>
    <script>
        $(function () {
            $('#test').speedometer();

            $('.changeSpeedometer').click(function () {
                $('#test').speedometer({ percentage: $('.speedometer').val() || 0 });
            });

        });
    </script>
</head>

<body>
    <center>
        <br><br><br>
        <input type="text" class="speedometer" value="90"></input>
        <button class="changeSpeedometer">Submit</button><br />
        <div id="test">90 </div>
    </center>
</body>
</html>

JS代码(jquery.jqcanvas-modified.js):

/*The MIT LicenseCopyright (c) 2008 David Kwast <david _dot_ kwast _at_ gmail>Permission is hereby granted,free of charge,to any person obtaining a copyof this software and associated documentation files (the "Software"),to dealin the Software without restriction,including without limitation the rightsto use,copy,modify,merge,publish,distribute,sublicense,and/or sellcopies of the Software,and to permit persons to whom the Software isfurnished to do so,subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS ORIMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHERLIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.*/
//keeps closure(function ($){
	var binded = false,verifySizeList = [],//jakemod:this variable used to be declared inside $.fn.jqcanvas->this.eachjqcanvas_id = $('canvas').size();
	$.fn.jqcanvas = function (callback,options){
	this.each(function (){
	var opts = $.extend({
}
,$.fn.jqcanvas.defaults,options),$this = $(this),top = $this.offset().top,left = $this.offset().left,width = getMasterWidth($this),height = getMasterHeight($this);
	/* jakemod:this variable used to assign ID based purely on number of canvas elements,but introduced bug if we are dynamically removing and inserting new canvases. Duplicate IDs were being generated,and un-targeted canvases would disappear since they shared an ID. */
//var jqcanvas_id = $('canvas').size();
	//jakemod:Simple increment ensures unique ID for every canvas elementjqcanvas_id += 1;
	var canvas_id = "jqcanvas_"+jqcanvas_id;
	$this.data("callback",callback);
	$this.data("top",top);
	$this.data("left",left);
	$this.data("width",width);
	$this.data("extraWidth",opts.extraWidth);
	$this.data("height",height);
	$this.data("jqcanvas_id",canvas_id);
	var canvas = $(create_canvas(canvas_id,top,left,width,height,$this,name,options));
	canvas.each(function (){
	redraw($this,this,options);
	//this == canvas element (not jquery obj)}
);
	if ( opts.verifySize ){
	verifySizeList.push($this);
	if ( !(binded) ){
	//Only bind this events once binded = true;
	setInterval(verifyResize,$.fn.jqcanvas.global_options.verifyResizeInterval);
	$(window).resize(verifyResize);
}
}
}
);
	return $(this);
}
;
	$.fn.jqcanvas.defaults ={
	extraWidth:0,verifySize:true}
$.fn.jqcanvas.global_options ={
	verifyResizeInterval:1000}
function hasMoved(master){
	var offset = master.offset();
	if (offset.top != master.data("top")){
	return true}
else if (offset.left != master.data("left")){
	return true}
else{
	return false}
;
}
function create_canvas(canvas_id,top,left,width,height,$this,name,options){
	var border_left = parseInt($this.css('borderLeftWidth')) || 0;
	var border_top = parseInt($this.css('borderTopWidth')) || 0;
	var position_left = parseInt(left);
	var position_top = parseInt(top);
	var new_position_left = (position_left+border_left).toString() + 'px' var new_position_top = (position_top+border_top).toString() + 'px' var canvasCSS ={
	zIndex:options.z || 1,position:"static"//,//left:new_position_left,// top:new_position_top}
;
	var new_width = width + $this.data("extraWidth");
	// Maybe we can refactor here var el = document.createElement('canvas');
	el.setAttribute('id',canvas_id);
	el.setAttribute('width',new_width);
	el.setAttribute('height',height);
	if($.browser.msie){
	G_vmlCanvasManager.initElement(el);
}
;
	var canvas = $(el);
	$this.prepend(canvas);
	canvas.data("classes",options.className);
	canvas.addClass("jqcanvas " + options.className );
	// canvas.width(width);
	// canvas.height(height);
	canvas.css(canvasCSS);
	return el;
}
function redraw(master,canvas,options){
	var width = getMasterWidth(master);
	var height = getMasterHeight(master);
	// Remove previous canvas and create it again with new width and height var canvas_id = master.data("jqcanvas_id");
	var name = $('#'+canvas_id).data('classes');
	$('#'+canvas_id).remove();
	canvas = create_canvas(canvas_id,master.data("top"),master.data("left"),width,height,master,name,options);
	master.data("jqcanvas",$(canvas));
	// Canvas size can be different from its master element size master.data("callback")(canvas,$(canvas).width(),$(canvas).height());
}
function move(master,canvas,top,left){
	$(canvas).css({
	top:top,left:left}
);
	// if($.browser.msie){
	// redraw(master,canvas);
	//}
}
function verifyMove(master,canvas){
	if (hasMoved(master)){
	var offset = master.offset();
	canvas.each(function(){
	move(master,this,offset.top,offset.left);
	//this == canvas element (not jquery obj)}
);
	master.data("top",offset.top);
	master.data("left",offset.left);
}
}
function getMasterWidth(master){
	return parseInt(master.css("padding-right")) + parseInt(master.css("padding-left")) + master.width()}
function getMasterHeight(master){
	return parseInt(master.css("padding-bottom")) + parseInt(master.css("padding-top")) + master.height()}
function hasResized(master){
	var width = getMasterWidth(master) var height = getMasterHeight(master) if (width != master.data("width")){
	return true}
else if (height != master.data("height")){
	return true}
else{
	return false}
;
}
function verifyResize(){
	jQuery.map(verifySizeList,function(master){
	var canvas = master.data("jqcanvas");
	verifyMove(master,canvas);
	if (hasResized(master)){
	canvas.each(function(){
	redraw(master,this);
	//this == canvas element (not jquery obj)}
);
	master.data("width",getMasterWidth(master));
	master.data("height",getMasterHeight(master));
}
}
);
}
}
)(jQuery);
	
附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
112.04 KB
jquery特效5
最新结算
jQuery密码强度插件Power PWChecker js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery密码强度插件Power PWChecker js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery密码强度插件Power PWChecker js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery图片随机排序推拽代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery图片随机排序推拽代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
C#获取磁盘或文件夹的空间信息(总大小,可用大小,已用大小)?
类型: .rar 金额: CNY 0.39¥ 状态: 待结算 详细>
C#获取磁盘或文件夹的空间信息(总大小,可用大小,已用大小)?
类型: .rar 金额: CNY 3.1¥ 状态: 待结算 详细>
HTM5 Canvas实现3D飞机飞行动画特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
HTM5 Canvas实现3D飞机飞行动画特效代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery图像缩放工具插件Zoomer特效代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章