博客园主题响应式布局

@date:2016-01-07 20:08:00

这里以主题darkgreentrip为例,其它主题类似。

响应式布局 #

在后台设置里页面定制CSS代码加上以下代码:

@-webkit-viewport {
   width: device-width;
}
@-moz-viewport {
   width: device-width;
}
@-ms-viewport {
   width: device-width;
}
@-o-viewport { 
   width: device-width;
}
@viewport {
   width: device-width; 
}

#main {
min-width: 0px !important; 
}

@media (max-width:990px) {
#home{ margin:0 15px; }
}
@media (max-width:640px) {
#sideBar, #mainContent{ width:100%;margin-right:0px !important;}
.post{ border-left:none; }
#mainContent .forFlow{margin-left:0em !important;}
#main { 
padding: 20px 0 0 0px;
overflow: hidden;
}
}

#navigator { height:auto; overflow:hidden; *zoom:1;}
#navList { float:left; }
#navList li { display: inline; float: none; }
}

此时还没有完成,因为少了meta里viewport的声明。

默认博客只有自定义css权限,自定义js等功能没有权限。需要发送邮件至contact@cnblogs.com联系管理员开发权限,原因可以按实说明,大概1天左右可以开通。会有邮件通知。

如果权限已开通,请在页首Html代码或者页脚Html代码加上以下代码:

<script type="text/javascript">
var meta = document.createElement('meta');
meta.setAttribute('name', 'viewport');
meta.setAttribute('content', 'initialwidth=device-width,initial-scale=1');
document.getElementsByTagName('head')[0].appendChild(meta);

</script>

这样就行了。

但是发现每次打开时慢慢的才变成响应式,其实直接使用下面这句就行:

<meta name="viewport" content="initial-scale=1, maximum-scale=1">

推荐、反对按钮悬浮 #

页面定制CSS代码加上以下代码:

#div_digg {
  position: fixed;
  bottom: -13px;
  right: 40px;
  z-index: 9999;
}
#div_digg {
  float: right;
  margin-bottom: 10px;
  margin-right: 30px;
  font-size: 12px;
  width: 125px;
  text-align: center;
  margin-top: 10px;
}

自动生成目录 #

页脚Html代码加上:

<style>
#sideToolbar {
	position: fixed;
	bottom: 20px;
	right: 25px;
	width: 250px;
}
#sideToolbar ul,#sideToolbar ol{
	padding: 0px;
}
#sideToolbar li{
	list-style: none;
}
#sideCatalog{
	background-color:#fff;
	padding-bottom:10px;
	border-radius:5px;
}
#sideCatalog-sidebar {
	-moz-border-bottom-colors: none;
	-moz-border-left-colors: none;
	-moz-border-right-colors: none;
	-moz-border-top-colors: none;
	background-color: #eaeaea;
	border-color: -moz-use-text-color #eaeaea;
	border-image: none;
	border-left: 1px solid #eaeaea;
	border-right: 1px solid #eaeaea;
	border-style: none solid;
	border-width: 0 1px;
	height: 353px;
	left: 5px;
	position: absolute;
	top: 0;
	width: 0
}
#sideCatalog-catalog {
  height: 325px;
  padding-top: 18px;
  overflow-y: scroll;
  overflow-x: hidden;
  padding-left: 23px;
  position: relative;
}
#sideCatalog #sideCatalog-sidebar .sideCatalog-sidebar-top {
	cursor: pointer;
	top: 0
}
#sideCatalog #sideCatalog-sidebar .sideCatalog-sidebar-bottom {
	bottom: 0
}
#sideCatalog #sideCatalog-sidebar .sideCatalog-sidebar-top,#sideCatalog #sideCatalog-sidebar .sideCatalog-sidebar-bottom {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll 0 -199px transparent;
	height: 10px;
	left: -5px;
	overflow: hidden;
	position: absolute;
	width: 10px
}
#sideCatalog li {
	margin: 0px;
	padding: 0 7px;
	text-align: left;
	position: relative
}
#sideCatalog li: hover {
	background-color: #f5f5f5
}
#sideCatalog-catalog ul .active {
	background-color: #f5f5f5
}
#sideCatalog-catalog .active a {
	color: #519cea
}
#sideCatalog-catalog a: hover {
	color: #519cea
}
#sideCatalog span: first-child {
	color: #999;
	font-family: Arial;
	font-size: 14px;
	font-weight: bold;
	padding-right: 5px
}
#sideCatalog li.h2Offset {
	padding-left: 45px;
	text-indent: -25px
}
#sideCatalog li.h3Offset {
	padding-left: 90px;
	text-indent: -50px
}
#sideCatalog a {
	text-decoration: none;
	color: #555;
	font-weight: bold
}
.sideCatalog-dot {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") repeat scroll 0 -222px transparent;
	cursor: pointer;
	font-size: 12px;
	height: 10px;
	left: -20px;
	line-height: 12px;
	overflow: hidden;
	position: absolute;
	top: 4px;
	width: 6px
}
#sideCatalog .highlight .sideCatalog-dot {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll -271px -38px transparent;
	height: 13px;
	left: -23px;
	top: 3px;
	width: 18px
}
#sideCatalogBtn {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll 0 0 transparent;
	cursor: pointer;
	display: block;
	height: 45px;
	margin-bottom: 5px;
	margin-left: 5px;
	position: relative;
	width: 45px;
	margin-top: 10px;
	outline: 0
}
#sideCatalogBtn: hover {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll -154px 0 transparent
}
.sideCatalogBtnDisable {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll -104px 0 transparent !important
}
#sideToolbar-up {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll -1px -62px transparent;
	border-radius: 2px;
	display: block;
	height: 45px;
	margin-left: 5px;
	width: 45px;
	outline: 0
}
#sideToolbar-up: hover {
	background: url("http://images.cnitblog.com/blog2015/294743/201503/111725133399017.gif") no-repeat scroll -74px -62px transparent
}
</style>

<script type="text/javascript">

  var a = $(document);
  a.ready(function () {
    var b = $('#mainContent'),
        d = 'sideToolbar',
        e = 'sideCatalog',
        f = 'sideCatalog-catalog',
        g = 'sideCatalogBtn',
        h = 'sideToolbar-up',
        i = '<div id="sideToolbar"style="display:none;">\<div class="sideCatalogBg"id="sideCatalog">\<div id="sideCatalog-sidebar">\<div class="sideCatalog-sidebar-top"></div>\<div class="sideCatalog-sidebar-bottom"></div>\</div>\<div id="sideCatalog-catalog">\<ul class="nav"style="width:225px;zoom:1">\</ul>\</div>\</div>\<a href="javascript:void(0);"id="sideCatalogBtn"class="sideCatalogBtnDisable"></a>\</div>',
        j = '',
        k = 200,
        l = 0,
        m = 0,
        n = 0,
        o, p = 113,
        q = true,
        r = true,
        s = b;
    if (s.length == 0) {
      return
    };
    b.append(i);
    o = s.find(':header');
    if (o.length > p) {
      r = false;
      var t = s.find('h1');
      var u = s.find('h2');
      if (t.length + u.length > p) {
        q = false
      }
    };

	if(o.length == 0) return;

    o.each(function (t) {
      var u = $(this),
            v = u[0];

      var title = u.text();
      var text = u.text();

      u.attr('id', 'autoid-' + l + '-' + m + '-' + n)
      //if (!u.attr('id')) {
      //    u.attr('id', 'autoid-' + l + '-' + m + '-' + n)
      //};
      if (v.localName === 'h1') {
        l++;
        m = 0;
        if (text.length > 14) text = text.substr(0, 12) + "...";
        j += '<li><span>' + l + '&nbsp&nbsp</span><a href="#' + u.attr('id') + '" title="' + title + '">' + text + '</a><span class="sideCatalog-dot"></span></li>';
      } else if (v.localName === 'h2') {
        m++;
        n = 0;
        if (q) {
          if (text.length > 12) text = text.substr(0, 10) + "...";
          j += '<li class="h2Offset"><span>' + l + '.' + m + '&nbsp&nbsp</span><a href="#' + u.attr('id') + '" title="' + title + '">' + text + '</a></li>';
        }
      } else if (v.localName === 'h3') {
        n++;
        if (r) {
          j += '<li class="h3Offset"><span>' + l + '.' + m + '.' + n + '&nbsp&nbsp</span><a href="#' + u.attr('id') + '" title="' + title + '">' + u.text() + '</a></li>';
        }
      }
    });
    $('#' + f + '>ul').html(j);
    b.data('spy', 'scroll');
    b.data('target', '.sideCatalogBg');

    $sideCatelog = $('#' + e);
    $('#' + g).on('click', function () {
      if ($(this).hasClass('sideCatalogBtnDisable')) {
        $sideCatelog.css('display', 'none')
      } else {
        $sideCatelog.css('display', '')
      };
      $(this).toggleClass('sideCatalogBtnDisable')
    });
$('#sideCatalogBtn').removeClass('sideCatalogBtnDisable')
 $sideCatelog.css('display', 'none');

    $sideToolbar = $('#' + d);
  $sideToolbar.css('display', 'block');



  });


</script>

参考:
1、【写漂亮的博客】让我们的博客更加漂亮,让我们的博客支持响应式布局! - 叶小钗 - 博客园
http://www.cnblogs.com/yexiaochai/archive/2013/05/27/3101311.html
2、自定义博客园皮肤:暗色流体响应式布局 - JiayangShen - 博客园
http://www.cnblogs.com/shn11160/archive/2013/03/23/2977123.html

Build by Loppo 0.6.14