博客园更改主题css样式js特效

 


一.申请js权限

 

1.进入博客园设置

 

2.进入博客设置

 

3.下拉,找到,博客侧边栏公告,有个申请j权限

上图为申请后样式.

注意:此权限仅对部分老用户开放,我本人申请了四次才通过,注册时间段的人多申请几次

 

二.更换官方主题

修改设置里可以修改官方提供的多种主题,可根据自己爱好挑选

 

三.自定义样式

将代码复制到对应栏,网上有各种牛人设计的样式,可以搜搜,我这里也是一个搬运工

 

在下面每个代码栏都贴上了一个小功能作为演示:

1.页面定制css样式

 

复制代码
  1. !--此处自定义标题背景色-->
  2. #cnblogs_post_body h1 {
  3. background: #265B8A;
  4. border-radius: 6px 6px 6px 6px;
  5. color: #FFFFFF;
  6. font-family: FZShuTi
  7. font-size: 23px;
  8. font-weight: bold;
  9. height: 25px;
  10. line-height: 25px;
  11. margin: 18px 0 !important;
  12. padding: 12px 0 8px 5px;
  13. text-shadow: 2px 2px 3px #222222;
  14. text-align:center;
  15. margin-bottom: 20px;
  16. }
  17. #cnblogs_post_body h2 {
  18. background-color: #008FC6;
  19. border-radius: 3px;
  20. text-align:center;
  21. color: white;
  22. text-shadow: 1px 1px 2px #222222;
  23. padding-left: 15px;
  24. margin-bottom: 12px;
  25. }
  26. #cnblogs_post_body h3 {
  27. background-color: #51C332;
  28. border-radius: 3px;
  29. text-align:center;
  30. color: white;
  31. text-shadow: 1px 1px 2px #222222;
  32. padding: 5px 15px;
  33. margin-bottom: 10px;
  34. width:50%
  35. }
  36. #cnblogs_post_body h4 {
  37. background-color: #5bc0de;
  38. border-radius: 3px;
  39. text-align:center;
  40. color: white;
  41. text-shadow: 1px 1px 2px #222222;
  42. padding: 5px 15px;
  43. margin-bottom: 10px;
  44. width:25%
  45. }
  46. code {
  47. padding: 1px 3px;
  48. margin: 0 3px;
  49. background: #ddd;
  50. border: 1px solid #ccc;
  51. font-family: Menlo,Monaco,Andale Mono,lucida console,Courier New,monospace;
  52. word-wrap: break-word;
  53. font-size: 14px;
  54. }
  55. #cnblogs_post_body table {
  56. text-align: center;
  57. width: 100%;
  58. border: 1px solid #dedede;
  59. margin: 15px 0;
  60. border-collapse: collapse;
  61. }
  62. #cnblogs_post_body table thead tr {
  63. background: #f8f8f8;
  64. }
  65. #cnblogs_post_body table tbody tr:hover {
  66. background: #efefef;
  67. }
  68. h1 a:visited,
  69. h1 a:link {
  70. color : green;
  71. }
  72. #top
  73. {
  74. color : red;
  75. }
这里贴上了更改标题的代码
复制代码

 

2.博客侧边栏公告

 

 

复制代码
  1. !-- 爱心特效 -->
  2. <script type="text/javascript">
  3. (function(window,document,undefined){
  4. var hearts = [];
  5. window.requestAnimationFrame = (function(){
  6. return window.requestAnimationFrame ||
  7. window.webkitRequestAnimationFrame ||
  8. window.mozRequestAnimationFrame ||
  9. window.oRequestAnimationFrame ||
  10. window.msRequestAnimationFrame ||
  11. function (callback){
  12. setTimeout(callback,1000/60);
  13. }
  14. })();
  15. init();
  16. function init(){
  17. css(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
  18. attachEvent();
  19. gameloop();
  20. }
  21. function gameloop(){
  22. for(var i=0;i<hearts.length;i++){
  23. if(hearts[i].alpha <=0){
  24. document.body.removeChild(hearts[i].el);
  25. hearts.splice(i,1);
  26. continue;
  27. }
  28. hearts[i].y--;
  29. hearts[i].scale += 0.004;
  30. hearts[i].alpha -= 0.013;
  31. hearts[i].el.style.cssText = "left:"+hearts[i].x+"px;top:"+hearts[i].y+"px;opacity:"+hearts[i].alpha+";transform:scale("+hearts[i].scale+","+hearts[i].scale+") rotate(45deg);background:"+hearts[i].color;
  32. }
  33. requestAnimationFrame(gameloop);
  34. }
  35. function attachEvent(){
  36. var old = typeof window.onclick==="function" && window.onclick;
  37. window.onclick = function(event){
  38. old && old();
  39. createHeart(event);
  40. }
  41. }
  42. function createHeart(event){
  43. var d = document.createElement("div");
  44. d.className = "heart";
  45. hearts.push({
  46. el : d,
  47. x : event.clientX - 5,
  48. y : event.clientY - 5,
  49. scale : 1,
  50. alpha : 1,
  51. color : randomColor()
  52. });
  53. document.body.appendChild(d);
  54. }
  55. function css(css){
  56. var style = document.createElement("style");
  57. style.type="text/css";
  58. try{
  59. style.appendChild(document.createTextNode(css));
  60. }catch(ex){
  61. style.styleSheet.cssText = css;
  62. }
  63. document.getElementsByTagName('head')[0].appendChild(style);
  64. }
  65. function randomColor(){
  66. return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";
  67. }
  68. })(window,document);
  69. </script>
这里贴一个点击出爱心的特效
复制代码

3.页首Html代码

  1. <canvasid="c_n9"width="1920"height="990"style="position: fixed; top: 0px; left: 0px; z-index: -1; opacity: 0.5;"></canvas>
  2.  
  3. <script src="https://files.cnblogs.com/files/siwuxie095/canvas-nest.min.js"></script>
背景特效,立体线条

4.页脚Html代码

 

复制代码
  1. <script language="javascript" type="text/javascript">
  2. // 生成目录索引列表
  3.  
  4. function GenerateContentList()
  5. {
  6. var mainContent = $('#cnblogs_post_body');
  7. var h2_list = $('#cnblogs_post_body h2');//如果你的章节标题不是h2,只需要将这里的h2换掉即可
  8.  
  9. if(mainContent.length < 1)
  10. return;
  11. if(h2_list.length>0)
  12. {
  13. var content = '<a name="_labelTop"></a>';
  14. content += '<div id="navCategory" style="color:#152e97;">';
  15. content += '<p style="font-size:18px;"><b>阅读目录</b></p>';
  16. content += '<ul>';
  17. for(var i=0; i<h2_list.length; i++)
  18. {
  19. var go_to_top = '<div style="text-align: right;"><a href="#_labelTop" style="color:#f68a33">回到顶部</a><a name="_label' + i + '"></a></div>';
  20. $(h2_list[i]).before(go_to_top);
  21. var h3_list = $(h2_list[i]).nextAll("h3");
  22. var li3_content = '';
  23. for(var j=0; j<h3_list.length; j++)
  24. {
  25. var tmp = $(h3_list[j]).prevAll('h2').first();
  26. if(!tmp.is(h2_list[i]))
  27. break;
  28. var li3_anchor = '<a name="_label' + i + '_' + j + '"></a>';
  29. $(h3_list[j]).before(li3_anchor);
  30. li3_content += '<li><a href="#_label' + i + '_' + j + '">' + $(h3_list[j]).text() + '</a></li>';
  31. }
  32. var li2_content = '';
  33. if(li3_content.length > 0)
  34. li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a><ul>' + li3_content + '</ul></li>';
  35. else
  36. li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a></li>';
  37. content += li2_content;
  38. }
  39. content += '</ul>';
  40. content += '</div><p>&nbsp;</p>';
  41. content += '<hr style="height:1px;border:none;border-top:1px dashed #0066CC;"/>';
  42. if($('#cnblogs_post_body').length != 0 )
  43. {
  44. $($('#cnblogs_post_body')[0]).prepend(content);
  45. }
  46. }
  47. }
  48. GenerateContentList();
  49. </script>
贴上 目录功能
复制代码

 

posted @   北寒-  阅读(3098)  评论(4编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示