Thursday, January 13, 2011

Mở rộng thành phần chứa nội dung bài viết

Như các bạn đều thấy dưới mỗi tiêu đề bài viết trên blog của tôi có 2 nút mũi tên sang trái và sang phải có chức năng mở rộng phần chứa nội dung bài viết và ẩn đi phần sidebar. Đây có thể nói là thủ thuật hàng hiếm trên cộng đồng Blogger.

Để làm được như vậy, ta phải sử dụng script tạo chức năng mở rộng phần content hay main-wrapper của Template (phần này chứa nội dung bài viết) và ẩn đi phần sidebar (thuộc tính display:none) khi ở chế độ mở rộng và định dạng chiều rộng của phần content tương đương với tổng chiều rộng của phần content cộng với phần sidebar ở chế độ thu hẹp.

Bước 1. Đăng nhập Blogger, vào Design &gt;&gt; Edit HTML. Đặt đoạn code sau đây vào trước thẻ </head>.

<script type='text/javascript'>
function enlarge(){
div = document.getElementById(&quot;sidebar&quot;);
div.style.display=&quot;none&quot;;
div = document.getElementById(&quot;content&quot;);
div.style.width=&quot;900px&quot;;
div.style.fontSize=&quot;16px&quot;;
}
function narrow(){
div = document.getElementById(&quot;sidebar&quot;);
div.style.display=&quot;&quot;;
div = document.getElementById(&quot;content&quot;);
div.style.width=&quot;600px&quot;;
div.style.fontSize=&quot;12px&quot;;
}
</script>

Lưu Template.

Bước 2. Chọn Expand Widget Tempplates. Tìm đoạn code

<div class='post-header'>
<div class='post-header-line-1'/>
</div>

Và đặt sau nó với đoạn code bên dưới.

<b:if cond='data:blog.pageType == &quot;item&quot;'>
<div style='float:right;margin:0px 0 5px 0px'>
<a href='javascript:narrow();'><img alt='Thu hẹp' src='http://bit.ly/dFogbx' title='Thu hẹp'/></a>
<a href='javascript:enlarge();'><img alt='Mở rộng' src='http://bit.ly/hLiV5F' title='Mở rộng'/></a><div style='clear: both;'/>
</div>
</b:if>

Lưu Template và kiểm tra kết quả được rồi đấy bạn.

Bạn nên tải về các file hình mũi tên leftarrowrightarrow hoặc tìm trên Internet để xài cho riêng bạn nhé.

No comments:

Post a Comment