[Thủ thuật Blogspot] Thêm giá trị % vào thanh cuộn

By
Advertisement
Khi truy cập vào trang blog của mình, khi bạn rê chuột hay kéo thanh cuộn của trình duyệt thì bạn sẽ thấy có số giá trị % hiển thị. Đây cũng là một thủ thuật khá hay, nhằm cho người dùng biết được họ kéo thanh cuộn của trình duyệt đi được bao nhiêu % so với vị trí ban đầu là ở trên cùng.
Hướng dẫn:

Bạn thêm đoạn code sau vào trước ]]></b:skin>
#scroll {
display: none;
position: fixed;
top: 0;
right: 20px;
z-index: 500;
padding: 3px 8px;
background-color: #737371;
color: #22FF27;
border-radius: 3px;
}
#scroll:after {
content: " ";
position: absolute;
top: 50%;
right: -8px;
height: 0;
width: 0;
margin-top: -4px;
border: 4px solid transparent;
border-left-color: #737371;
}
Bạn thêm đoạn code sau vào dưới thẻ đóng </head>
<div id='scroll'></div>
Bạn thêm đoạn code sau vào trước thẻ đóng </body>
<script type='text/javascript'>
//<![CDATA[
var scrollTimer = null;
$(window).scroll(function() {
   var viewportHeight = $(this).height(),
       scrollbarHeight = viewportHeight / $(document).height() * viewportHeight,
       progress = $(this).scrollTop() / ($(document).height() - viewportHeight),
       distance = progress * (viewportHeight - scrollbarHeight) + scrollbarHeight / 2 - $('#scroll').height() / 2;
    $('#scroll')
        .css('top', distance)
        .text(' (' + Math.round(progress * 100) + '%)')
        .fadeIn(100);
    if (scrollTimer !== null) {
        clearTimeout(scrollTimer);
    }
    scrollTimer = setTimeout(function() {
        $('#scroll').fadeOut();
    }, 1500);
});
//]]>
</script>
Cuối cùng bạn lưu mẫu lại.

Chúc bạn thành công!

0 nhận xét:

Đăng nhận xét