1. 程式人生 > 實用技巧 >部落格園模板相關程式碼

部落格園模板相關程式碼

/*點選sideCatalogBtn
if($(this).hasClass('sideCatalogBtnDisable')) {
    alert("隱藏");
    $("#sideToolbar").css('position', 'unset');
} else {
    alert("顯示");
    $("#sideToolbar").css('position', 'fixed');
};
*/

支援Js程式碼

<!-- 側邊欄 -->
<script type="text/javascript">
    //以下是錨點JS
var a = $(document);
a.ready(
function() { var b = $('body'), 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, //限制存在個數,如數量過多,則只顯示h2,不顯示h3 //o, p = 13, o, p = 100, q = true, r = true, s = b; if(s.length === 0) { return }; b.append(i); //指定獲取目錄的範圍-------------這一點非常重要,因為每個人指定的範圍都不一樣,所以這是要修改的地方 //o = s.find(':header'); o = $('#cnblogs_post_body').find(':header')
if(o.length > p) { r = false; var t = s.find('h2'); var u = s.find('h3'); if(t.length + u.length > p) { q = false } }; 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 === 'h2') { l++; m = 0; if(text.length > 14) text = text.substr(0, 20) + "..."; 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 === 'h3') { m++; n = 0; if(q) { if(text.length > 12) text = text.substr(0, 16) + "..."; j += '<li class="h2Offset"><span>' + l + '.' + m + '&nbsp&nbsp</span><a href="#' + u.attr('id') + '" title="' + title + '">' + text + '</a></li>'; } } else if(v.localName === 'h4') { 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'); $('body').scrollspy({ target: '.sideCatalogBg' }); $sideCatelog = $('#' + e); $('#' + g).on('click', function() { if($(this).hasClass('sideCatalogBtnDisable')) { $sideCatelog.css('visibility', 'hidden') $sideToolbar.css('position', 'unset'); } else { $sideCatelog.css('visibility', 'visible') $sideToolbar.css('position', 'fixed'); }; $(this).toggleClass('sideCatalogBtnDisable') }); $('#' + h).on('click', function() { $("html,body").animate({ scrollTop: 0 }, 500) }); $sideToolbar = $('#' + d); //通過判斷評論框是否存在顯示索引目錄 var commentDiv = $("#blog-comments-placeholder"); a.on('scroll', function() { //評論框存在才呼叫方法 if(commentDiv.length > 0) { var t = a.scrollTop(); if(t > k) { $sideToolbar.css('display', 'block'); $('#gotop').show() } else { $sideToolbar.css('display', 'none') $('#gotop').hide() } } }) }); //以上是錨點JS //以下是返回頂部JS $(function() { $('body').append('<div id="gotop" onclick="goTop();"></div>'); }); function goTop(u, t, r) { var scrollActivate = !0; if(scrollActivate) { u = u || 0.1; t = t || 16; var s = 0, q = 0, o = 0, p = 0, n = 0, j = 0; document.documentElement && (s = document.documentElement.scrollLeft || 0, q = document.documentElement.scrollTop || 0); document.body && (o = document.body.scrollLeft || 0, p = document.body.scrollTop || 0); n = window.scrollX || 0; j = window.scrollY || 0; s = Math.max(s, Math.max(o, n)); q = Math.max(q, Math.max(p, j)); p = 1 + u; window.scrollTo(Math.floor(s / p), Math.floor(q / p)); < s || 0 < q ? window.setTimeout('goTop(' + u + ', ' + t + ')', t) : 'undefined' != typeof r && r() } else { scrollActivate = !0 } } //以上是返回頂部JS </script> <!--點選愛心特效--> <script type="text/javascript"> //需要jquery外掛 /* 滑鼠特效 */ var a_idx = 0; jQuery(document).ready(function($) { $("body").click(function(e) { var a = new Array("❤不做鹹魚!❤","❤拒絕懶惰!❤","❤想做吃貨❤","❤拒絕單身❤","❤向大佬學習❤","❤扶我起來~❤","❤come on❤","❤一直在路上~❤","❤累了~❤","❤再趴一會❤","❤66666❤","❤高興的飛起*****❤"); var $i = $("<span></span>").text(a[a_idx]); a_idx = (a_idx + 1) % a.length; var x = e.pageX, y = e.pageY; $i.css({ "z-index": 999999999999999999999999999999999999999999999999999999999999999999999, "top": y - 20, "left": x, "position": "absolute", "font-weight": "bold", "color": "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")" }); $("body").append($i); $i.animate({ "top": y - 180, "opacity": 0 }, 1500, function() { $i.remove(); }); }); });

頁首HTML程式碼

<link  type="text/css" rel="stylesheet" href="http://files.cnblogs.com/files/miangao/maodian.css">
<style type="text/css">
#sideCatalogBtn{
  margin:0;
  position:fixed;
  bottom:20px;
  right:225px;
}
#sideToolbar{
   /*position:unset*/
}
</style>