以前有个想法,能不能用JS动态创建CANVAS绘制图案当网页背景,在网络发现有现成的别人已经实现的:GeoPattern

代码如下:

<!DOCTYPE html>  
<html>  
<head>  
<title>js 生成随机背景图</title>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
<style>
html, body{
margin:0; padding:0; width:100%; height:100%;
}
</style>
</head>  
<body>
<script>
$(function(){
    var option = {
        //color:'#060',     // 前景色
        //baseColor:'#006', // 背景色
        //generator:'plusSigns', // 样式
    };
    var pattern = GeoPattern.generate('GitHub' + Math.random(), option);
    $('body').css('background-image', pattern.toDataUrl());
});
</script>
</body>  
</html>  

 

参考资料:

https://github.com/btmills/geopattern

http://btmills.github.io/geopattern/

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2022-01-27
  • 2022-01-03
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-25
  • 2021-06-05
  • 2021-08-22
  • 2021-06-19
  • 2021-12-05
相关资源
相似解决方案