原文出处: http://www.codefans.net/jscss/code/4593.shtml
jquery.scratchie.js图片刮奖插件实例演示代码,可实现类似刮奖的效果,刮刮乐中的基本效果。引用了google的API,jquery版本1.4.4,需要几张图片配合,已附在代码里,运行效果后右键-->图片另存为下载素材图片。本效果兼容性也不错,可用于网页刮奖游戏中。

<!DOCTYPE html>
<head>
<title>jQuery类似刮刮乐的图片刮奖插件jquery.scratchie.js</title>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", "1.4.4");</script>
<script type="text/javascript">
//以下代码原型为jquery.scratchie.js
(function($){$.fn.scratchie = function(options) {var settings = {cursor: '/jscss/demoimg/201310/coin.gif', cursorHeight: 20, cursorWidth: 20,target : 'target',img : '/jscss/demoimg/201310/prize.jpg',imgHeight : 200, imgWidth : 400,title : 'Are you feeling lucky today?', fillColor : '#cc0000', fillImg : '/jscss/demoimg/201310/overlay.jpg', fillX : 20, fillY : 20,completion: 70, uncoverOnComplete : true, requireMouseClick : true,callback: function(){alert('Congratulations!');}};if(options){if(typeof options == 'object'){$.extend(settings, options);}else{settings.target = options;}}var mousedown = false;var ready = false;var overlaysTotal = overlaysUncovered = 0;var mouseUpAfterDrag = function(){$().one('mouseup', function(){mousedown = false;$().unbind();$('.scratch_overlay').bind('mousedown', mouseUpAfterDrag);});return false;}var mouseMove = function(e){$('#cursor').css({'left' : e.clientX - 2, 'top' : e.clientY + 2});}var mouseEnter = function(){$('#cursor').show();return false;}var mouseOut = function(){$('#cursor').hide();return false;}this.each(function (){var t, target, tp, ov, spritex, spritey;t = $(this);target = $('#' + settings.target);t.css({'cursor' : 'url(blank.cur), none','height' : settings.imgHeight + 'px','width' : settings.imgWidth + 'px'});target.attr({'alt' : settings.title,'title' : settings.title,'zIndex' : 1}).css({'height' : settings.imgHeight + 'px','width' : settings.imgWidth + 'px',}).bind('mousedown', function(){return false;});tp = target.position();tt = tp.top;tl = tp.left;spritex = spritey = 0;t.after('<div id="cursor" style="cursor:none;width:' + settings.cursorWidth + 'px;height:' + settings.cursorHeight + 'px;position:fixed;display:none;top:0;left:0;z-index:10000;background:url(' + settings.cursor + ') top left no-repeat;"></div>');ov = '';for(i=0; i < settings.imgWidth; i += settings.fillX){for(j = 0; j < settings.imgHeight; j += settings.fillY){++overlaysTotal;ov += '<div class="scratch_overlay" style="z-index:100;height:' + settings.fillY + 'px;width:' + settings.fillX + 'px;position:absolute;border:0;overflow:hidden;top:' + (tt + j) + 'px;left:' + (tl + i) + 'px;background:';if(settings.fillImg){ov += ' transparent url(' + settings.fillImg + ') -' + spritex + 'px -' + spritey + 'px no-repeat;';spritey += settings.fillY;}else{ov += settings.fillColor;}ov += '"/>';}if(settings.fillImg){spritey = 0;spritex += settings.fillX;}}t.after(ov);target.attr('src', settings.img);$('.scratch_overlay').css('cursor', 'url(blank.cur), none');target.bind('mouseout', function(){mouseOut();}).bind('mouseenter', function(){mouseEnter();}).bind('mousemove', function(e){mouseMove(e);});$('.scratch_overlay').bind('mouseout', function(){mouseOut();}).bind('mouseenter', function(){mouseEnter();}).bind('mousemove', function(e){mouseMove(e);});if(settings.requireMouseClick === true){$('.scratch_overlay').bind('mousedown', function(){mousedown = true;// fix to recognize mouseup event after moving mousemouseUpAfterDrag();if(ready === true){++overlaysUncovered;$(this).remove();}return false;});}$('.scratch_overlay').bind('mouseover', function(){if(mousedown === true || settings.requireMouseClick === false){if(ready === true){++overlaysUncovered;$(this).remove();}if((overlaysUncovered / overlaysTotal) * 100 >= settings.completion){if(settings.uncoverOnComplete === true){$('.scratch_overlay').remove();}settings.callback();}}});ready = true;});return this;};
})(jQuery);
</script>
<style type="text/css">
body{font-size: 11px;font-family:Verdana, Geneva, sans-serif;}
a{color:#FF9900;text-decoration: none;}
a:hover, a:active{background:#FF9900;color:#eee;}
img{border:0;}
#container{width: 640px;margin: 40px auto 0;position:relative;}
#content{width: 640px;margin-top: 20px;}
pre{border:1px dashed #222;padding:4px;}
</style>
<script type="text/javascript">
$(document).ready(function(){$('#raspadinha').scratchie({target : 'target',img : '/jscss/demoimg/201310/prize.jpg',imgHeight : 200, imgWidth : 400,title : 'Try your luck!',fillImg : '/jscss/demoimg/201310/overlay.jpg',requireMouseClick : true,callback: function(){alert('Congratulations!');}});$('#lang_pt').click(function(){$('.en').fadeOut(function(){$('.pt').show();});});$('#lang_en').click(function(){$('.pt').fadeOut(function(){$('.en').show();});});
});
$(window).load(function(){setTimeout(function(){$('#aw').slideDown(320);}, 1150);
});
</script>
</head>
<body>
<div id="container">
<div id="content">
<div id="raspadinha">
<img id="target" />
</div><!-- raspadinha -->
</div><!--content-->
</div><!--container-->
</body>
</html>

JavaScript刮奖效果(jquery图片刮奖插件)相关推荐

  1. 网站项目必备——12款白富美型 jQuery 图片轮播插件

    转自:http://www.cnblogs.com/lhb25/archive/2013/01/06/jquery-image-carousel-effect.html 图片轮播是网站中的常用功能,用 ...

  2. jQuery图片自动添加水印插件

    JS脚本(jQuery)为图片加水印效果预览: http://hovertree.com/texiao/jquery/94/ 本功能使用HTML5实现,可为图片加上文字水印,可设置文字,设置颜色,位置 ...

  3. html轮播图水平传送带,经典的白富美型jQuery图片轮播插件

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...

  4. 支持响应式手机端jQuery图片轮播插件unslider

    支持响应式手机端jQuery图片轮播插件unslider,非常强大的jQuery插件,支持响应式手机端.支持函数回调.支持左右按钮切换,可以自定义是否使用响应式fluid:true/false.是否显 ...

  5. jQuery 图片轮播插件

    网站项目必备--12款经典的白富美型 jQuery 图片轮播插件 图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的  ...

  6. html图片展示插件,12款经典的白富美型—jquery图片轮播插件—前端开发必备

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...

  7. 12款经典的白富美型 jQuery 图片轮播插件

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的  jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精 ...

  8. 网站项目必备——12款经典的白富美型 jQuery 图片轮播插件

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...

  9. html轮播鼠标悬停效果,jQuery图片轮播加悬停效果

    插件描述:jQuery图片轮播加悬停效果 =======以下内容由会员 只看不发了 提供============ 使用方法 1.将文档内内部样式表保存到目录css下的style.css文件中,并在页面 ...

最新文章

  1. HTML4.0标准语法--字体
  2. 前端编程提高之旅(五)----写给大家看的css书
  3. Leetcode264. Ugly Number II丑数2
  4. c# groupbox大小,C# 实现可拖动和调整大小的控件
  5. Vue组件通信原理剖析(一)事件总线的基石 $on和$emit
  6. ASP.NET Core 2.1 : 十一. 如何在后台运行一个任务
  7. eeprom 数据偶尔变成ff_关于水电站冗余配置下监控系统下发调节令偶尔不动作的案例分析...
  8. Python 错误小结
  9. C# 使用NPlot绘图
  10. python 屏幕代码雨效果(已验证)
  11. Nightwish全部专辑320kbs全集下载
  12. 记录mysql in和not in 效率低下的问题
  13. 个人永久性免费-Excel催化剂功能第85波-灵活便捷的批量发送短信功能(使用腾讯云接口)...
  14. “嗲”上海文化,女人需要学会的4种气质
  15. 多模态理论张德禄_学术会议 | 适用语言学与多模态国际会议
  16. vue项目中使用ckplayer.js封装视频播放组件
  17. UVA1149 装箱 Bin Packing 题解
  18. nyoj304节能(区间dp)
  19. photo-sphere-viewer4 全景图插件应用
  20. easyUI 添加ComboTree 字段到一个 form

热门文章

  1. 关于PS课程中字体部分的学习总结
  2. 用户态和内核态的切换耗费时间的原因
  3. 经验分享!java程序员面试十多家公司后的经验心得
  4. c学习笔记 文件输入/ 输出 20210314
  5. 调用百度文字识别API
  6. 第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结
  7. 《用C#制作PDF文件全攻略》
  8. 20小时写一篇文章,好看到爆炸的手机壁纸都在这些App里!
  9. 数据挖掘期末复习速成大法 华南农业大学
  10. Node fs同步、异步写入文件(一)