一些原生的js小特效

这篇博客分享了四个使用原生JavaScript实现的网页特效,包括鼠标跟随画布特效、下雪场景、加载样式以及一个滑块验证效果,其中滑块验证效果存在一些小问题。
摘要由CSDN通过智能技术生成

一.这是一个鼠标跟随特效(使用画布)
html部分

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<canvas id="c" style="width: 100%;height: 100%;"></canvas>
		<script src="tx.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
	</body>
</html>

js部分

window.onload = function(){
	C = Math.cos;
	S = Math.sin;
	U = 0;
	w = window;
	j = document;
	d = j.getElementById('c');
	c = d.getContext('2d');  //通过一个方法来获取可以调用一切 Canvas API 的入口
	W = d.width = w.innerWidth;
	H = d.height = w.innerHeight;
	c.fillRect(0,0,W,H); //左上角 x 坐标, 左上角 y 坐标, 宽度, 高度
	c.globalCompositeOperation = 'lighter';
	c.lineWidth = 0.2;
	c.lineCap = 'round';
	
	var bool = 0;
	    t = 0;
	    d.onmousemove = function(e){
	    	if(window.T){
	    		if(D == 9){
	    			D = Math.random()*15;
	    			f(1);
	    		}
	    		clearTimeout(T);
	    	}
	    	X = e.pageX;
	    	Y = e.pageY;
	    	a = 0;
	    	b = 0;
	    	A = X;
	    	B = Y;
	    	R = (e.pageX / W*999 >> 0 ) / 999;
	    	r = (e.pageY / H*999 >> 0) / 999;
	    	U = e.pageY / H *360 >> 0;
	    	D = 9;
	    	g = 360 * Math.PI / 100;
	    	T = setInterval(f = function(e){
	    		c.save();
	    		c.globalCompositeOperation = 'source-over';
	    		if(e != 1){
	    			c.fillStyle = 'rgba(0,0,0,0.02)';
	    			c.fillRect(0,0,W,H);	
	    		}
	    		c.restore();
	    		i = 25;
	    		while(i--){
	    			c.beginPath();
	    			if(D > 450 || bool){
	    			 if (!bool) { 
                        bool = 1;
                    }
                    if (D < 0.1) { 
                        bool = 0;
                    }
                    t -= g; 
                    D -= 0.1; 
                }
                if (!bool) {
                    t += g; 
                    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值