在页面中引入jquery和jquery.waterrippleeffect.min.js文件。
1 2 | < script src = 'path/to/js/jquery.min.js' ></ script > < script src = 'path/to/js/jquery.waterrippleeffect.min.js' ></ script > |
使用一个<div>作为该水波纹动画特效的HTML结构:
1 | < div id = "holder" ></ div > |
初始化插件
通过纯js的方式来调用该水波纹动画效果的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | function init() { //Settings - params for WaterRippleEffect var settings = { image: './img/SwimmingPool.jpg' , //背景图片 rippleRadius: 3, //radius of the ripple width: 480, //width height: 480, //height delay: 1, //if auto param === true. 1 === 1 second delay for animation auto: true //if auto param === true, animation starts on it′s own }; //------------------------------------------------------------------------ //standalone //初始化 var waterRippleEffect = new WaterRippleEffect(document.getElementById( 'holder' ), settings); document.getElementById( 'holder' ).style.cursor = 'pointer' ; //鼠标点击事件 document.getElementById( 'holder' ).addEventListener( 'click' , function (e) { var mouseX = e.layerX; var mouseY = e.layerY; waterRippleEffect.disturb(mouseX, mouseY); }); //鼠标移动事件 document.getElementById( 'holder' ).addEventListener( 'mousemove' , function (e) { var mouseX = e.layerX; var mouseY = e.layerY; waterRippleEffect.disturb(mouseX, mouseY); }); |
通过jquery插件的方式来调用该水波纹动画效果的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $( '#holder' ).waterRippleEffect(settings); $( '#holder' ).css( 'cursor' , 'pointer' ); //鼠标点击事件 $( '#holder' ).click( function (e) { var mouseX = e.pageX - $( this ).offset().left; var mouseY = e.pageY - $( this ).offset().top; $( '#holder' ).waterRippleEffect( "disturb" , mouseX, mouseY); }); //鼠标移动事件 $( '#holder' ).mousemove( function (e) { var mouseX = e.pageX - $( this ).offset().left; var mouseY = e.pageY - $( this ).offset().top; $( '#holder' ).waterRippleEffect( "disturb" , mouseX, mouseY); }); |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com