[HỎI] Cố định Navbar theo thanh cuộn trang cho XenForo

Thảo luận trong 'Style & Template Questions' bắt đầu bởi datdaik000, 1/1/15.

1votes
5/5, 1 vote

  1. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    Trước em có làm rồi nhưng mà gỡ mất:( Giờ tìm lại thì không thấy nữa:(( Ai biết làm hoặc làm rồi thì share cho em với:x Thanks mọi người nhiều nhiều>:D<
     
    Last edited: 3/1/15
    Đang tải...
  2. satsujin

    satsujin Member

    Bài viết:
    100
    Likes :
    14
    vãi cả demo =)) Tưởng demo site nào có float nav chứ bác vác site bác lên làm gì, quảng cáo trá hình à
     
  3. satsujin

    satsujin Member

    Bài viết:
    100
    Likes :
    14
  4. thanhthanh

    thanhthanh Moderator Staff Member

    Bài viết:
    477
    Likes :
    133
    cho vào cuối navigation
    <script>
    jQuery("document").ready(function($){

    var nav = $('#navigation');

    $(window).scroll(function () {
    if ($(this).scrollTop() > 205) {
    nav.addClass("f-nav pageWidth");
    } else {
    nav.removeClass("f-nav pageWidth");
    }
    });

    });
    </script>

    Bạn muốn khi vào nó dính thì sửa 205.

    CHo vào EXTRA.css

    .f-nav
    {
    z-index: 9999;
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    right: 0;
    }
     
    maidaiduong and datdaik000 like this.
  5. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    em có dám quảng cáo đâu bác:( Trước site em có làm rồi mà gỡ ra:( Cái thanh nav giữ nguyên, khi di chuyển xuống thì nó di chuyển theo chứ không phải cho nó lên top như bác @thanhthanh hướng dẫn. Dù sao cũng cảm ơn 2 bác:(
    p/s: em đã xóa cái "demo" đi rồi nha bác:))
     
    Last edited: 3/1/15
  6. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    thanks mọi người, em làm được rồi>:D<
     
  7. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    bác share đoạn code của bác cho mình với bác @datdaik000 ! Thanks
     
  8. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    code đây:D mình làm theo bài viết này
    - Tạo 1 template float_navigation mới với nội dung sau:
    Mã:
    <script type="text/javascript">
    $(function() {
    $(window).scroll(function(){
    ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) ?
    $('#header').stop().animate({'opacity':'0.5'},400).css({'position':'fixed','top':'-{xen:calc '@headerLogoHeight + @headerTabHeight - 25'}px','z-index':'60'}):
    $('#header').stop().animate({'opacity':'1'},400).css({'position':'absolute','top':'0px'});
    });
    $('#header').hover(
    function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);},
    function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'0.5'},400);}
    );
    });
    </script>
    - TÌm template page_container_js_body và thêm vào cuối đoạn code sau:
    Mã:
    <xen:include template="float_navigation" />
    End code!
     
  9. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    Thanks bác rất nhiều nhé, dùng OK cho xen 1.4.3 chứ bác? Update các version Xen có xung đột gì không? bác dùng thấy sao?
    (có phải rebuild cache các kiểu hok bác?)
    Thân!
     
  10. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    mình đang dùng Xen 1.4.3 nhé:D
     
  11. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    cứ copy code bác add vào Template mới tạo là OK men hả bác?
    Sao mình thấy site bác Navibar vẫn ko đứng yên nhỉ?
    Thân!
     
    Last edited: 3/1/15
  12. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    OK rồi bác, rất cảm ơn, nếu muốn cái navibar không tự trong suốt trước khi rê chuột thì chỉnh sao OK bác!
    Thân!
     
  13. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    thế thì thay toàn bộ code ở template float_navigation thành thế này là được:
    Mã:
    <script type="text/javascript">
    $(function() {
        $(window).scroll(function(){
            ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) ?
                $('#header').stop().animate({'opacity':'1'},400).css({'position':'fixed','top':'-110px','z-index':'60'}):
                $('#header').stop().animate({'opacity':'1'},400).css({'position':'absolute','top':'0px'});
        });
        $('#header').hover(
            function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);},
            function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);}
        );
    });
    </script>
    
     
  14. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    RẤT CẢM ƠN BÁC NHIỀU NHÉ!
    Chúc site bác luôn phát triển!
    CN vui vẻ!
    Thân!
     
  15. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    thanks bác:D
     
  16. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    Sorry, lại làm phiền bác, Em làm theo mà hok được bác à!, cái Navibar nó không đứng yên theo code mới bác vừa share:

    Em dùng lại code cũ nhưng sửa lại 2 chỗ 0.5 thành 1 thì có OK không bác?

    <script type="text/javascript">
    $(function() {
    $(window).scroll(function(){
    ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) ?
    $('#header').stop().animate({'opacity':'
    1'},400).css({'position':'fixed','top':'-{xen:calc '@headerLogoHeight + @headerTabHeight - 25'}px','z-index':'60'}):
    $('#header').stop().animate({'opacity':'1'},400).css({'position':'absolute','top':'0px'});
    });
    $('#header').hover(
    function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);},
    function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'
    1'},400);}
    );
    });
    </script>

    Thân mến!
     
  17. datdaik000

    datdaik000 D.C Style

    Bài viết:
    380
    Likes :
    86
    Mình cũng sửa lại mấy chỗ 0.5 thành 1 mà bạn:D Sửa như bạn cũng ok!
    Code trước:
    Mã:
    <script type="text/javascript">
    $(function() {
        $(window).scroll(function(){
            ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) ?
                $('#header').stop().animate({'opacity':'0.5'},400).css({'position':'fixed','top':'-110px','z-index':'60'}):
                $('#header').stop().animate({'opacity':'1'},400).css({'position':'absolute','top':'0px'});
        });
        $('#header').hover(
            function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);},
            function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'0.5'},400);}
        );
    });
    </script>
    
    Code sau:
    Mã:
    <script type="text/javascript">
    $(function() {
        $(window).scroll(function(){
            ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) ?
                $('#header').stop().animate({'opacity':'1'},400).css({'position':'fixed','top':'-110px','z-index':'60'}):
                $('#header').stop().animate({'opacity':'1'},400).css({'position':'absolute','top':'0px'});
        });
        $('#header').hover(
            function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);},
            function(){ if ($(window).scrollTop() > {xen:calc '@headerLogoHeight + (@headerTabHeight * 2)'}) $(this).stop().animate({'opacity':'1'},400);}
        );
    });
    </script>
    
     
  18. tpoclub

    tpoclub Member

    Bài viết:
    84
    Likes :
    36
    vâng, cảm ơn bác! chắc mắt e muốn đi khám!
    Nhờ bác học hỏi thêm được cái code mà e thích
    Thân! :)
     
  19. maidaiduong

    maidaiduong New Member

    Bài viết:
    10
    Likes :
    1
    Mình làm thử thì thấy chuẩn luôn, Thanks bạn đã share

     
  20. thanhthanh

    thanhthanh Moderator Staff Member

    Bài viết:
    477
    Likes :
    133
    Theo mình thì đây là cách đơn giản nhất, nhẹ nhất, không những áp dụng cho navigation mà còn áp dụng cho tabLink hay bất cứ vị trí nào
     
    datdaik000 thích bài này.
comments powered by Disqus

Chia sẻ trang này

Đang tải...