前端代码分享——星空背景特效(内含源码)

这篇具有很好参考价值的文章主要介绍了前端代码分享——星空背景特效(内含源码)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


前端代码分享——星空背景特效(内含源码),前端炫酷代码分享,全部文章,前端

运行演示

前端代码分享——星空背景特效(内含源码),前端炫酷代码分享,全部文章,前端

前端代码分享——星空背景特效(内含源码),前端炫酷代码分享,全部文章,前端
打开网页效果最好哦

提供的JavaScript代码是一个名为"WarpDrive"的jQuery插件,它创建了一个星空动画,类似于科幻媒体(如《星际迷航》)中所看到的"超光速"效果。

核心代码


( function() {

    function WarpDrive( element, params ) {

        var settings = {};
            settings.width = 480;
            settings.height = 480;
            settings.autoResize = false;
            settings.autoResizeMinWidth = null;
            settings.autoResizeMaxWidth = null;
            settings.autoResizeMinHeight = null;
            settings.autoResizeMaxHeight = null;
            settings.addMouseControls = true;
            settings.addTouchControls = true;
            settings.hideContextMenu = true;
            settings.starCount = 6666;
            settings.starBgCount = 2222;
            settings.starBgColor = { r:255, g:255, b:255 };
            settings.starBgColorRangeMin = 10;
            settings.starBgColorRangeMax = 40;
            settings.starColor = { r:255, g:255, b:255 };
            settings.starColorRangeMin = 10;
            settings.starColorRangeMax = 100;
            settings.starfieldBackgroundColor = { r:0, g:0, b:0 };
            settings.starDirection = 1;
            settings.starSpeed = 20;
            settings.starSpeedMax = 200;
            settings.starSpeedAnimationDuration = 2;
            settings.starFov = 300;
            settings.starFovMin = 200;
            settings.starFovAnimationDuration =  2;
            settings.starRotationPermission = true;
            settings.starRotationDirection = 1;
            settings.starRotationSpeed = 0.0;
            settings.starRotationSpeedMax = 1.0;
            settings.starRotationAnimationDuration = 2;
            settings.starWarpLineLength = 2.0;
            settings.starWarpTunnelDiameter = 100;
            settings.starFollowMouseSensitivity = 0.025;
            settings.starFollowMouseXAxis = true;
            settings.starFollowMouseYAxis = true;
            
        //---

        if ( params !== undefined ) {

            for ( var prop in params ) {

                if ( params.hasOwnProperty( prop ) && settings.hasOwnProperty( prop ) ) {

                    settings[ prop ] = params[ prop ];

                }

            }

        }

        //---

        for ( var prop in settings ) {

            if ( settings.hasOwnProperty( prop ) && prop.indexOf( 'Duration' ) > -1 ) {

                settings[ prop ] = settings[ prop ] * 60;

            }

        }

        if ( typeof settings.starBgColor === 'string' && settings.starBgColor.indexOf( '#' ) > -1 ) {

            settings.starBgColor = hexToRgb( settings.starBgColor );

        } else if ( typeof settings.starBgColor === 'string' && settings.starBgColor.indexOf( 'rgb' ) > -1 ) {

            settings.starBgColor = parseRGBString( settings.starBgColor );

        }

        if ( typeof settings.starColor === 'string' && settings.starColor.indexOf( '#' ) > -1 ) {

            settings.starColor = hexToRgb( settings.starColor );

        } else if ( typeof settings.starColor === 'string' && settings.starColor.indexOf( 'rgb' ) > -1 ) {

            settings.starColor = parseRGBString( settings.starColor );

        }

        if ( typeof settings.starfieldBackgroundColor === 'string' && settings.starfieldBackgroundColor.indexOf( '#' ) > -1 ) {

            settings.starfieldBackgroundColor = hexToRgb( settings.starfieldBackgroundColor );

        } else if ( typeof settings.starfieldBackgroundColor === 'string' && settings.starfieldBackgroundColor.indexOf( 'rgb' ) > -1 ) {

            settings.starfieldBackgroundColor = parseRGBString( settings.starfieldBackgroundColor );

        }

        if ( !element ) {

            throw Error( '\n' + 'No div element found' );

        }

        //---

        var MATHPI180 = Math.PI / 180;
        var MATHPI2 = Math.PI * 2;

        var canvasWidth = settings.width;
        var canvasHeight = settings.height;

        var starCount = settings.starCount;
        var starBgCount = settings.starBgCount;

        var starBgColor = settings.starBgColor;
        var starBgColorRangeMin = settings.starBgColorRangeMin
        var starBgColorRangeMax = settings.starBgColorRangeMax
        var starColor = settings.starColor;
        var starColorRangeMin = settings.starColorRangeMin;
        var starColorRangeMax = settings.starColorRangeMax;

        var starfieldBackgroundColor = settings.starfieldBackgroundColor;

        var starDirection = settings.starDirection;

        var starSpeed = settings.starSpeed;
        var starSpeedMin = starSpeed;
        var starSpeedMax = settings.starSpeedMax;
        var starSpeedAnimationDuration = settings.starFovAnimationDuration;
        var starSpeedAnimationTime = 0;

        var starFov = settings.starFov;
        var starFovMin = settings.starFovMin;
        var starFovMax = starFov;
        var starFovAnimationDuration =  settings.starFovAnimationDuration;
        var starFovAnimationTime = starFovAnimationDuration;

        var starRotation = 0.0;
        var starRotationPermission = settings.starRotationPermission;
        var starRotationDirection = settings.starRotationDirection;
        var starRotationSpeed = settings.starRotationSpeed;
        var starRotationSpeedMin = starRotationSpeed;
        var starRotationSpeedMax = settings.starRotationSpeedMax;
        var starRotationAnimationDuration = settings.starRotationAnimationDuration;
        var starRotationAnimationTime = 0;
        
        var starWarpLineLength = settings.starWarpLineLength;
        var starWarpTunnelDiameter = settings.starWarpTunnelDiameter;
        var starFollowMouseSensitivity = settings.starFollowMouseSensitivity;
        var starFollowMouseXAxis = settings.starFollowMouseXAxis;
        var starFollowMouseYAxis = settings.starFollowMouseYAxis;
        var starDistance = 8000;

        var starBorderFront = -starFovMin + 1;
        var starBorderBack = starDistance;

        var starHolder;
        var starBgHolder;
        var starColorLookupTable;
        var starBgColorLookupTable;

        var canvas, ctx, imageData, pix;

        var center;

        var mouseActive;
        var mouseDown;
        var mousePos;

        var paused = false;

        //---

        function init() {

            canvas = document.createElement( 'canvas' );
            canvas.style.backgroundColor = rgbToHex( starfieldBackgroundColor.r, starfieldBackgroundColor.g, starfieldBackgroundColor.b );
            canvas.setAttribute( 'width', canvasWidth );
            canvas.setAttribute( 'height', canvasHeight );

            if ( settings.addMouseControls ) {

                canvas.addEventListener( 'mousemove', mouseMoveHandler, false );
                canvas.addEventListener( 'mousedown', mouseDownHandler, false );
                canvas.addEventListener( 'mouseup', mouseUpHandler, false );
                canvas.addEventListener( 'mouseenter', mouseEnterHandler, false ); 
                canvas.addEventListener( 'mouseleave', mouseLeaveHandler, false ); 

            }

            if ( settings.addTouchControls ) {

                canvas.addEventListener( 'touchstart', touchStartHandler, false );
                canvas.addEventListener( 'touchend', touchEndHandler, false );
                canvas.addEventListener( 'touchmove', touchMoveHandler, false );
                canvas.addEventListener( 'touchcancel', touchCancelHandler, false );

            }

            if ( settings.hideContextMenu ) {

                canvas.oncontextmenu = function( e ) {

                    e.preventDefault();

                };

            }

            element.appendChild( canvas );

            //---

            ctx = canvas.getContext( '2d' );
            imageData = ctx.getImageData( 0, 0, canvasWidth, canvasHeight );
            pix = imageData.data;

            //---

            center = { x:canvas.width / 2, y:canvas.height / 2 };

            mouseActive = false;
            mouseDown = false;
            mousePos = { x:center.x, y:center.y };

            //---

            starColorLookupTable = [];
            starBgColorLookupTable = [];
            starHolder = [];
            starBgHolder = [];

            addColorLookupTable( starColorLookupTable, starColorRangeMin, starColorRangeMax, starfieldBackgroundColor, starColor );
            addColorLookupTable( starBgColorLookupTable, starBgColorRangeMin, starBgColorRangeMax, starfieldBackgroundColor, starBgColor );
            addStars();
            animloop();

            //---

            if ( settings.autoResize ) {

                window.addEventListener( 'resize', resizeHandler );

                resize();

            }

        };

        //---

        Math.easeInQuad = function( t, b, c, d ) {

            return c * t * t / ( d * d ) + b;

        };

        Math.easeOutQuad = function( t, b, c, d ) {

            return -c * t * t / ( d * d ) + 2 * c * t / d + b;

        };

        //---
        //http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors

        function shadeBlend( p, c0, c1 ) {

            var n = p < 0 ? p * -1 : p, u = Math.round, w = parseInt;
            var f = w( c0.slice( 1 ), 16 ), t = w( ( c1 ? c1 : p < 0 ? '#000000' : '#FFFFFF' ).slice( 1 ), 16 ), R1 = f >> 16, G1 = f >> 8 & 0x00FF, B1 = f & 0x0000FF;

            return '#' + ( 0x1000000 + ( u ( ( ( t >> 16 ) - R1 ) * n ) + R1 ) * 0x10000 + ( u ( ( ( t >> 8 & 0x00FF ) - G1 ) * n ) + G1 ) * 0x100 + ( u ( ( ( t & 0x0000FF ) - B1 ) * n ) + B1 ) ).toString( 16 ).slice( 1 );

        };

        //---
        //http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb

        function hexToRgb( hex ) {

            var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;

            hex = hex.replace( shorthandRegex, function( m, r, g, b ) {

                return r + r + g + g + b + b;

            } );

            var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( hex );

            return result ? {

                r: parseInt( result[ 1 ], 16 ),
                g: parseInt( result[ 2 ], 16 ),
                b: parseInt( result[ 3 ], 16 )

            } : null;

        };

        function rgbToHex( r, g, b ) {

            var rgb = b | ( g << 8 ) | ( r << 16 );

            return '#' + ( 0x1000000 + rgb ).toString( 16 ).slice( 1 );

        };

        //---

        function parseRGBString( rgbString ) {

            rgbString = rgbString.replace( /\s+/g, '' );

            var rgbValues = rgbString.split( '(' )[ 1 ].split( ')' )[ 0 ].split( ',' );

            return { r:rgbValues[ 0 ], g:rgbValues[ 1 ], b:rgbValues[ 2 ] };

        }

        //---

        function clearImageData() {

            for ( var i = 0, l = pix.length; i < l; i += 4 ) {

                pix[ i ]     = starfieldBackgroundColor.r;
                pix[ i + 1 ] = starfieldBackgroundColor.g;
                pix[ i + 2 ] = starfieldBackgroundColor.b;
                pix[ i + 3 ] = 0;

            }

        };

        function setPixelAdditive( x, y, r, g, b, a ) {

            var i = ( x + y * canvasWidth ) * 4;

            pix[ i ]     = pix[ i ]     + r;
            pix[ i + 1 ] = pix[ i + 1 ] + g;
            pix[ i + 2 ] = pix[ i + 2 ] + b;
            pix[ i + 3 ] = a;
            
        };

        //---

        function drawLine( x1, y1, x2, y2, r, g, b, a ) {

            var dx = Math.abs( x2 - x1 );
            var dy = Math.abs( y2 - y1 );

            var sx = ( x1 < x2 ) ? 1 : -1;
            var sy = ( y1 < y2 ) ? 1 : -1;

            var err = dx - dy;

            var lx = x1;
            var ly = y1;    
            
            while ( true ) {

                if ( lx > -1 && lx < canvasWidth && ly > -1 && ly < canvasHeight ) {

                    setPixelAdditive( lx, ly, r, g, b, a );

                }

                if ( ( lx === x2 ) && ( ly === y2 ) )
                    break;

                var e2 = 2 * err;

                if ( e2 > -dx ) { 

                    err -= dy; 
                    lx += sx; 

                }

                if ( e2 < dy ) { 

                    err += dx; 
                    ly += sy; 

                }

            }

        };

        //---

        function addColorLookupTable( colorLookupTable, colorRangeMin, colorRangeMax, colorRGBStart, colorRGBEnd ) {

            var colorHexStart = rgbToHex( colorRGBStart.r, colorRGBStart.g, colorRGBStart.b );
            var colorHexEnd   = rgbToHex( colorRGBEnd.r, colorRGBEnd.g, colorRGBEnd.b );

            var colorRange = [];
            var colorEndValues = [];

            var percent;

            var i, l, j, k;

            for ( i = 0, l = 100; i <= l; i++ ) {

                percent = i / 100;

                colorRange.push( shadeBlend( percent, colorHexStart, colorHexEnd ) );

            }

            for ( i = 0, l = colorRangeMax - colorRangeMin; i <= l; i++ ) {

                var index = i + colorRangeMin;

                colorEndValues.push( colorRange[ index ] );

            }

            for ( i = 0, l = colorEndValues.length; i < l; i++ ) {

                colorRange = [];

                for ( j = 0, k = 100; j <= k; j++ ) {

                    percent = j / 100;

                    colorRange.push( hexToRgb( shadeBlend( percent, colorHexStart, colorEndValues[ i ] ) ) );


                }

                colorLookupTable.push( colorRange );

            }

        };
        
        //---

        function getStarPosition( radius, sideLength ) {

            var x = Math.random() * sideLength - ( sideLength / 2 );
            var y = Math.random() * sideLength - ( sideLength / 2 );

            if ( radius > 0 ) {

                while ( Math.sqrt( x * x + y * y ) < radius ) {

                    x = Math.random() * sideLength - ( sideLength / 2 );
                    y = Math.random() * sideLength - ( sideLength / 2 );

                }

            }

            return { x:x, y:y };

        };

        function addStar( x, y, z, ox, oy, oz ) {

            var star = {};
                star.x = x;
                star.y = y;
                star.z = z;
                star.ox = ox;
                star.oy = oy;
                star.x2d = 0;
                star.y2d = 0;
          
            return star;

        };

        function addStars() {

            var i;

            var x, y, z;

            var star, starPosition;

            for ( i = 0; i < starBgCount; i++ ) {

                starPosition = getStarPosition( 0, 20000 );

                x = starPosition.x;
                y = starPosition.y;
                z = Math.round( Math.random() * starDistance );

                star = addStar( x, y, z, x, y, z );
                star.colorIndex = Math.floor( Math.random() * starBgColorLookupTable.length );
                star.colorLookupTable = starBgColorLookupTable[ star.colorIndex ];
                star.color = star.colorLookupTable[ Math.floor( Math.random() * 100 ) ];

                starBgHolder.push( star );

            }

            for ( i = 0; i < starCount; i++ ) {

                starPosition = getStarPosition( starWarpTunnelDiameter, 10000 );

                x = starPosition.x;
                y = starPosition.y;
                z = Math.round( Math.random() * starDistance );

                star = addStar( x, y, z, x, y, z );
                star.distance = starDistance - z;
                star.distanceTotal = Math.round( starDistance + starFov );
                star.colorIndex = Math.floor( Math.random() * starColorLookupTable.length );
                star.colorLookupTable = starColorLookupTable[ star.colorIndex ];
                star.color = star.colorLookupTable[ Math.floor( ( star.distance / star.distanceTotal ) * 100 ) ];

                starHolder.push( star );

            }

        };

        //---

        window.requestAnimFrame = ( function() {

            return  window.requestAnimationFrame       ||
                    window.webkitRequestAnimationFrame ||
                    window.mozRequestAnimationFrame    ||
                    function( callback ) {
                        window.setTimeout( callback, 1000 / 60 );
                    };

        } )();

        function animloop() {

            requestAnimFrame( animloop );

            if ( !paused ) {

                render();

            }

        };

        //---

        function render() {

            clearImageData();

            //---

            var i, j, l, k, m, n;

            //---

            var star;
            var scale;

            //---

            if ( starRotationPermission ) {

                if ( mouseDown ) {

                    starRotationAnimationTime += 1;

                    if ( starRotationAnimationTime > starRotationAnimationDuration )
                        starRotationAnimationTime = starRotationAnimationDuration;

                } else {

                    starRotationAnimationTime -= 1;

                    if ( starRotationAnimationTime < 0 )
                        starRotationAnimationTime = 0;

                }

                starRotationSpeed = Math.easeOutQuad( starRotationAnimationTime, starRotationSpeedMin, starRotationSpeedMax, starRotationAnimationDuration );
                starRotation -= starRotationSpeed * starRotationDirection;
                
            }

            //---
            
            if ( mouseActive ) {

                starSpeedAnimationTime += 1;

                if ( starSpeedAnimationTime > starSpeedAnimationDuration )
                    starSpeedAnimationTime = starSpeedAnimationDuration;

                starFovAnimationTime -= 1;

                if ( starFovAnimationTime < 0 )
                    starFovAnimationTime = 0;

                //---

                if ( starFollowMouseXAxis ) {

                    center.x += ( mousePos.x - center.x ) * starFollowMouseSensitivity;

                }

                if ( starFollowMouseYAxis ) {

                    center.y += ( mousePos.y - center.y ) * starFollowMouseSensitivity;

                }

            } else {

                starSpeedAnimationTime -= 1;

                if ( starSpeedAnimationTime < 0 )
                    starSpeedAnimationTime = 0;

                starFovAnimationTime += 1;

                if ( starFovAnimationTime > starFovAnimationDuration )
                    starFovAnimationTime = starFovAnimationDuration;

                //---

                if ( starFollowMouseXAxis ) {

                    center.x += ( ( canvas.width / 2 ) - center.x ) * starFollowMouseSensitivity;

                }

                if ( starFollowMouseYAxis ) {

                    center.y += ( ( canvas.height / 2 ) - center.y ) * starFollowMouseSensitivity;

                }

            }

            starSpeed = Math.easeOutQuad( starSpeedAnimationTime, 0, starSpeedMax - starSpeedMin, starSpeedAnimationDuration ) + starSpeedMin;
            starFov = Math.easeInQuad( starFovAnimationTime, 0, starFovMax - starFovMin, starFovAnimationDuration ) + starFovMin;

            //---

            starBorderFront = -starFov + 1;

            //---

            var warpSpeedValue = starSpeed * ( starSpeed / ( starSpeedMax / starWarpLineLength ) );

            //---
            //stars bg

            for ( i = 0, l = starBgHolder.length; i < l; i++ ) {

                star = starBgHolder[ i ];

                scale = starFov / ( starFov + star.z ); 
                
                star.x2d = ( star.x * scale ) + center.x; 
                star.y2d = ( star.y * scale ) + center.y; 

                if ( star.x2d > -1 && star.x2d < canvasWidth && star.y2d > -1 && star.y2d < canvasHeight ) {

                    setPixelAdditive( star.x2d | 0, star.y2d | 0, star.color.r, star.color.g, star.color.b, 255 );

                }

            }
            
            //---
            //stars moving

            for ( i = 0, l = starHolder.length; i < l; i++ ) {

                star = starHolder[ i ];

                //---
                //star distance calc

                star.distanceTotal = Math.round( starDistance + starFov );

                //---
                //star movement

                if ( starDirection >= 0 ) {

                    star.z -= starSpeed;
                    star.distance += starSpeed;

                    if ( star.z < starBorderFront ) {

                        star.z = starBorderBack;
                        star.distance = 0;

                    }  

                } else {

                    star.z += starSpeed;
                    star.distance -= starSpeed;

                    if ( star.z > starBorderBack ) {

                        star.z = starBorderFront;
                        star.distance = star.distanceTotal;

                    }

                }

                //---
                //star color

                star.color = star.colorLookupTable[ Math.floor( ( star.distance / star.distanceTotal ) * 100 ) ];

                //---
                //star position & draw
                
                scale = starFov / ( starFov + star.z ); 
                
                star.x2d = ( star.x * scale ) + center.x; 
                star.y2d = ( star.y * scale ) + center.y; 

                if ( starSpeed === starSpeedMin ) {

                    if ( star.x2d > -1 && star.x2d < canvasWidth && star.y2d > -1 && star.y2d < canvasHeight ) {

                        setPixelAdditive( star.x2d | 0, star.y2d | 0, star.color.r, star.color.g, star.color.b, 255 );

                    }

                } else {

                    var nz = star.z + warpSpeedValue;

                    scale = starFov / ( starFov + nz ); 

                    var x2d = ( star.x * scale ) + center.x; 
                    var y2d = ( star.y * scale ) + center.y; 

                    if ( x2d > -1 && x2d < canvasWidth && y2d > -1 && y2d < canvasHeight ) {

                        drawLine( star.x2d | 0, star.y2d | 0, x2d | 0, y2d | 0, star.color.r, star.color.g, star.color.b, 255 );

                    }

                }

                //---
                //star rotation

                if ( starRotationSpeed !== starRotationSpeedMin ) {

                    var radians = MATHPI180 * starRotation;

                    var cos = Math.cos( radians );
                    var sin = Math.sin( radians );

                    star.x = cos * star.ox + sin * star.oy;
                    star.y = cos * star.oy - sin * star.ox;

                }
  
            }

            //---

            ctx.putImageData( imageData, 0, 0 );

        };

        function resizeHandler( event ) {

            resize();

        };

        function resize() {

            canvasWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
            canvasHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

            if ( settings.autoResizeMinWidth && canvasWidth < settings.autoResizeMinWidth ) {

                canvasWidth = settings.autoResizeMinWidth;

            } else if ( settings.autoResizeMaxWidth && canvasWidth > settings.autoResizeMaxWidth ) {

                canvasWidth = settings.autoResizeMaxWidth;

            }

            if ( settings.autoResizeMinHeight && canvasHeight < settings.autoResizeMinHeight ) {

                canvasHeight = settings.autoResizeMinHeight;

            } else if ( settings.autoResizeMaxHeight && canvasHeight > settings.autoResizeMaxHeight ) {

                canvasHeight = settings.autoResizeMaxHeight;

            }

            //---

            canvas.setAttribute( 'width', canvasWidth );
            canvas.setAttribute( 'height', canvasHeight );

            center = { x:canvas.width / 2, y:canvas.height / 2 };

            //---

            imageData = ctx.getImageData( 0, 0, canvasWidth, canvasHeight );
            pix = imageData.data;

        };

        //---

        function mouseMoveHandler( event ) {

            mousePos = getMousePos( canvas, event );

        };

        function mouseEnterHandler( event ) {

            mouseActive = true;

        };

        function mouseLeaveHandler( event ) {

            mouseActive = false;
            mouseDown = false;

        };

        function mouseDownHandler( event ) {

            mouseDown = true;

        };

        function mouseUpHandler( event ) {

            mouseDown = false;

        };

        //---

        function getMousePos( canvas, event ) {

            var rect = canvas.getBoundingClientRect();
            
            return { x: event.clientX - rect.left, y: event.clientY - rect.top };

        };

        //---

        function touchStartHandler( event ) {

            event.preventDefault();

            mouseDown = true;
            mouseActive = true;

        };

        function touchEndHandler( event ) {

            event.preventDefault();

            mouseDown = false;
            mouseActive = false;

        };

        function touchMoveHandler( event ) {

            event.preventDefault();

            mousePos = getTouchPos( canvas, event );

        };

        function touchCancelHandler( event ) {

            mouseDown = false;
            mouseActive = false;

        };

        //---

        function getTouchPos( canvas, event ) {

            var rect = canvas.getBoundingClientRect();

            return { x: event.touches[ 0 ].clientX - rect.left, y: event.touches[ 0 ].clientY - rect.top };

        };

        //---

        this.pause = function() {

            paused = true;

        };

        this.unpause = function() {

            paused = false;

        };

        //---

        init();

    };

    window.WarpDrive = WarpDrive;

} () );

if ( typeof jQuery !== 'undefined' ) {

    ( function( $ ) {

        $.fn.warpDrive = function( params ) {

            var args = arguments;

            return this.each( function() {

                if ( !$.data( this, 'plugin_WarpDrive' ) ) {

                    $.data( this, 'plugin_WarpDrive', new WarpDrive( this, params ) );

                } else {

                    var plugin = $.data( this, 'plugin_WarpDrive' );

                    if ( plugin[ params ] ) {

                        plugin[ params ].apply( this, Array.prototype.slice.call( args, 1 ) );

                    } else {

                        $.error( 'Method ' +  params + ' does not exist on jQuery.warpDrive' );

                    }

                }

            } );

        };
        
    } ( jQuery ) );

}

提供的JavaScript代码是一个名为"WarpDrive"的jQuery插件,它创建了一个星空动画,类似于科幻媒体(如《星际迷航》)中所看到的"超光速"效果。文章来源地址https://www.toymoban.com/news/detail-632297.html

到了这里,关于前端代码分享——星空背景特效(内含源码)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 前端代码分享——常用的手机端底部导航栏(内含源码)

    点击左上角 打开网页 效果更佳哦 index.html js 代码的解释: 代码以一些注释开始,提到了设计师和原始图片来源。 代码使用\\\"use strict\\\"启用JavaScript的严格模式,这有助于捕捉常见的编码错误并强制执行更好的编码实践。 代码选择HTML文档中的body元素,并将其分配给 body 变量。

    2024年02月03日
    浏览(47)
  • 分享几款节日实用前端动画特效(附效果图及在线预览)

    分享7款有趣也实用的前端动画特效 其中有CSS动画、canvas动画、js小游戏等等 下方效果图可能不是特别的生动 那么你可以点击在线预览进行查看相应的动画特效 同时也是可以下载该资源的 基于canvas实现的一款节日背景动画 当鼠标悬停时会在悬停处不断的冒爱心等动画效果

    2024年01月20日
    浏览(74)
  • HTML5 Canvas与JavaScript携手绘制动态星空背景

    目录 一、程序代码 二、代码原理 三、运行效果 这段代码通过 HTML5 的 canvas 元素和 JavaScript 实现了一个星空背景效果。首先,它在页面加载时创建了一个全屏大小的画布,并使用 JavaScript 生成了多个具有不同运动轨道的星星对象。每颗星星都具有随机的半径、位置、运动速度

    2024年02月20日
    浏览(53)
  • Qt使用星空图作为窗口背景,点击键盘的WASD控制小飞机在上面移动。

    事件函数的使用依托于Qt的事件机制,一个来自于外部事件的传递机制模型如下所示 信号槽虽然好用,但是无法包含所有的情况,事件函数可以起到对信号槽无法覆盖的一些时机进行补充,事件函数的使用无需连接。 常用的事件函数如下所示。 // 绘制事件 void QWidget :: pain

    2024年02月11日
    浏览(48)
  • 金蝶云星空各种部署架构及适用场景分享

    随着公司的快速发展上市到进入世界500强,作为技术经理,负责了金蝶云·星空从单点部署到集群,再到替换SAP的过程,如今项目已经成功上线,所以对金蝶的相关知识也做下整理和归档。 在项目实施过程中,部署架构是非常重要的一个设计,否则面对不同的企业规模和业务

    2024年02月07日
    浏览(102)
  • chatGPT 学习分享:内含PPT分享下载

    InstructGPT 论文地址: Training language models to follow instructions with human feedback chatGPT地址:openAI 个人整理的PPT(可编辑),下载地址:chatGPT学习分享PPT

    2024年02月15日
    浏览(45)
  • 用python画星空的代码简单,python星空浪漫表白源码

    大家好,小编来为大家解答以下问题,用python画星空的代码简单,python星空浪漫表白源码,今天让我们一起来看看吧! 用python画星空源代码是什么? 用python画星空源代码是from turtle import * from random import random,randint screen = Screen() width ,height = 800,600 screen.setup(width,height) screen.ti

    2024年02月07日
    浏览(43)
  • EDA软件—Cadence学习笔记分享(内含安装教程)

    作为流行的EDA工具之一,Cadence一直以来以其强大的功能受到广大EDA工程师的青睐。Cadence可以完成整个IC设计流程的各个方面。 Cadence 软件是一个功能强大的系统工具,包括很多功能模块,如原理图输入: 数字、模拟及混合电路仿真:自动布局、布线:印刷电路板图及生产制造数

    2024年02月07日
    浏览(44)
  • 用python代码画一幅星空

    运行代码后,会在画布上画出一些大小不同、位置随机的白色星星,就像是一幅星空一样。你可以根据自己的需求修改代码,调整画布大小、星星数量和大小等参数,让画出来的星空更加逼真。 效果如图所示  

    2024年02月11日
    浏览(45)
  • 前端技术搭建井字游戏(内含源码)

    上周我们实通过前端基础实现了飞机大战游戏,今天还是继续按照我们原定的节奏来带领大家完成一个井字游戏游戏,功能也比较简单简单,也是想借助这样一个简单的功能,然后来帮助大家了解我们JavaScript在前端中的作用, 在前面的文章当中我们也提及到我们在本系列的

    2024年02月05日
    浏览(50)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包