Cách giữ tiêu đề bài viết khi cuộn trang.
Trong demo hôm trước mình giới thiệu với mọi người một template chuyên cho web hài.
(DEMO)
Bạn thấy đó khi cuộn trang xuống dưới thì tiêu đề luôn được giữ lại trước khi chuyển sang tiêu đề khác.
Trong bài viết này mình sẽ share đoạn code này để mọi người có thể làm được như vậy :
Download Code : Download
Cách áp dụng tới Blogger :
Bước 1: Mở chế độ chỉnh sửa:
Bạn vào Dashbroad -> Mẫu -> Chỉnh sửa HTML
<h3 class='post-title entry-title'
Đặt toàn bộ thẻ h3 này trong : <div class='followMeBar'>Đặt vào đây</div>
Giống như hình :
Bước 3: Thêm trước </head> đoạn code Javascript sau :
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
function stickyTitles(stickies) {
this.load = function() {
stickies.each(function(){
var thisSticky = jQuery(this).wrap('<div class="followWrap" />');
thisSticky.parent().height(thisSticky.outerHeight());
jQuery.data(thisSticky[0], 'pos', thisSticky.offset().top);
});
}
this.scroll = function() {
stickies.each(function(i){
var thisSticky = jQuery(this),
nextSticky = stickies.eq(i+1),
prevSticky = stickies.eq(i-1),
pos = jQuery.data(thisSticky[0], 'pos');
if (pos <= jQuery(window).scrollTop()) {
thisSticky.addClass("fixed");
if (nextSticky.length > 0 && thisSticky.offset().top >= jQuery.data(nextSticky[0], 'pos') - thisSticky.outerHeight()) {
thisSticky.addClass("absolute").css("top", jQuery.data(nextSticky[0], 'pos') - thisSticky.outerHeight());
}
} else {
thisSticky.removeClass("fixed");
if (prevSticky.length > 0 && jQuery(window).scrollTop() <= jQuery.data(thisSticky[0], 'pos') - prevSticky.outerHeight()) {
prevSticky.removeClass("absolute").removeAttr("style");
}
}
});
}
}
jQuery(document).ready(function(){
var newStickies = new stickyTitles(jQuery(".followMeBar"));
newStickies.load();
jQuery(window).on("scroll", function() {
newStickies.scroll();
});
});
</script>
<style type="text/css">
.followMeBar {
border-bottom: solid 1px #111;
border-top: solid 1px #444;
padding: 1%;
position: relative;
z-index: 1;
}
.followMeBar.fixed {
position: fixed;
top: 0;
width: 98%;
z-index: 0;
}
.followMeBar.fixed.absolute {
position: absolute;
}
</style>
Ok. Save Template và bạn Test thử. Sau đó chỉnh lại cho phù hợp.
Ghi rõ nguồn erhay khi bạn phát hành thông tin từ trang này




Ôi tìm hoài không thấy. Cảm ơn bạn ad rất nhiều
ReplyDeletechưa thấy send e cái template hài thế thế bác ơi
ReplyDeleteBan oi giup minh lam mot trang wep duoc khong?
ReplyDeleteBạn có thể tự làm được. nếu bạn không biết ở đâu có thể vào đây hỏi mình sẽ giúp.
ReplyDeletebác ơi
ReplyDeletexong cái webtretho của e chưa bác
e hóng quá :3
bác giúp e với
cái phần hot, xem nhiều của bạn làm như thế nào vậy, giúp mình với, mình làm hoài mà không có làm được.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteBạn thêm CSS này là được :
ReplyDelete.PopularPosts .widget-content ul li {
padding: 3px !important;
border-bottom: 1px solid #e0e0e0 !important;;
}
ul li {
list-style-type: none !important;;
}
.PopularPosts .item-thumbnail {
float: left !important;;
margin: 0 5px 5px 0 !important;;
}
a{font:verdana !important}
a:link, a:visited {
color: #5c74c8 !important;
text-decoration: none !important;
outline: none !important;
font-weight: 200 !important;
}
.PopularPosts .item-title {
padding-bottom: 0.2em !important;;
font-size:12px !important;;
}
ul li a {
list-style-type: none !important;;
font-size: 11px !important !important;;
}
.PopularPosts img {
width: 65px !important;
height: 50px !important;
padding-right: .4em !important;;
}