码迷,mamicode.com
首页 > Web开发 > 详细

HTML5 Canvas水波纹动画特效

时间:2018-06-10 18:58:59      阅读:796      评论:0      收藏:0      [点我收藏+]

标签:src   top   pre   实用   splay   特效   margin   .com   ref   

HTML5的Canvas特性非常实用,我们不仅可以在Canvas画布上绘制各种图形,也可以制作绚丽的动画,比如这次介绍的水波纹动画特效。以前我们也分享过一款基于HTML5 WebGL的水波荡漾动画,让人惊叹不已,这次分享的HTML5 Canvas水波纹动画同样非常震撼人心。

技术分享图片

 在线演示          源码下载

 

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML5 Canvas水波纹动画特效DEMO演示</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/zzsc.css">
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script> 
<script type="text/javascript" src="js/jquery.waterrippleeffect.min.js"></script>
<style type="text/css">
     html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, font, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    b, u, i, center,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td {
        margin: 0;
        padding: 0;
        border: 0;
        outline: 0;
        font-size: 100%;
        vertical-align: baseline;
        /*background: transparent;*/
        box-sizing: border-box;
    }

    body {
        overflow: hidden;
    }
    .container{
        width: 480px;
        height: 480px;
        margin:20px auto;
        position: relative;
    }
    .clear {
        clear: both;
        height: 0;
        font-size: 0;
        line-height: 0;
    }
</style>
 <script>

    $( document ).ready( function() {

        //------------------------------------------------------------------------

        $( #preloaderDiv ).delay( 1000 ).fadeTo( 1000 , 0, function() {

            $( this ).css( display, none );

        } );

        $( #startDiv ).css( cursor, pointer ).click( function() {

            //$( this ).css( ‘display‘, ‘none‘ );

            $( this ).delay( 10 ).fadeTo( 1000 , 0, function() {

                $( this ).css( display, none );

            } );

            init();

        } );

        //------------------------------------------------------------------------

        function init() {

            //Settings - params for WaterRippleEffect
            var settings = {

                image: ./img/SwimmingPool.jpg,//image path
                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

            //init
            
            var waterRippleEffect = new WaterRippleEffect( document.getElementById( holder ), settings );
            document.getElementById( holder ).style.cursor = pointer;

            //on click
            
            document.getElementById( holder ).addEventListener( click, function( e ) {

                var mouseX = e.layerX;
                var mouseY = e.layerY;

                waterRippleEffect.disturb( mouseX, mouseY );

            } );
            

            //on mousemove
            
            document.getElementById( holder ).addEventListener( mousemove, function( e ) {

                var mouseX = e.layerX;
                var mouseY = e.layerY;

                waterRippleEffect.disturb( mouseX, mouseY );

            } );
            
            //------------------------------------------------------------------------

            //jQuery

            //init
            /*
            $( ‘#holder‘ ).waterRippleEffect( settings );
            $( ‘#holder‘ ).css( ‘cursor‘, ‘pointer‘ );
            */

            //on click
            /*
            $( ‘#holder‘ ).click( function( e ) {

                var mouseX = e.pageX - $( this ).offset().left;
                var mouseY = e.pageY - $( this ).offset().top;

                $( ‘#holder‘ ).waterRippleEffect( "disturb", mouseX, mouseY );

            } );
            */

            //on mousemove
            /*
            $( ‘#holder‘ ).mousemove( function( e ) {

                var mouseX = e.pageX - $( this ).offset().left;
                var mouseY = e.pageY - $( this ).offset().top;

                $( ‘#holder‘ ).waterRippleEffect( "disturb", mouseX, mouseY );

            } );
            */

        };

        //------------------------------------------------------------------------

    } );
    
</script>
</head>
<body>
<div class="container">
    <div id=‘holder‘ style=‘width:480px; height:480px; position:absolute;‘></div>

    <div id=‘startDiv‘ style=‘background-color:#000; position:absolute; width:480px; height:480px;‘>
            
        <img src=‘img/startBt.jpg‘ width=‘480px‘ height=‘480px‘ alt=‘Start‘ style=‘position:absolute; top:50%; left:50%; margin-top:-240px; margin-left:-240px;‘>

    </div>
    
    <div id=‘preloaderDiv‘ style=‘background-color:#000; position:absolute; width:480px; height:480px; pointer-events:none‘>
        
        <img src=‘img/PreloaderDark.gif‘ width=‘44px‘ height=‘48px‘ alt=‘Preloader‘ style=‘position:absolute; top:50%; left:50%; margin-top:-22px; margin-left:-24px;‘>

    </div>
</div>

<div style="text-align:center;clear:both;">
<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
<script src="/follow.js" type="text/javascript"></script>
</div>

</body>
</html>

 

 

HTML5 Canvas水波纹动画特效

标签:src   top   pre   实用   splay   特效   margin   .com   ref   

原文地址:https://www.cnblogs.com/ltb6w/p/9163977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!