Làm menu giống trượt theo giống vegaviet.com

Thảo luận trong 'Style & Template Questions' bắt đầu bởi davidhuynhvan, 10/10/13.

1votes
5/5, 1 vote

  1. davidhuynhvan

    davidhuynhvan Member

    Bài viết:
    116
    Likes :
    22
    Đang tải...
  2. davidhuynhvan

    davidhuynhvan Member

    Bài viết:
    116
    Likes :
    22
    Menu này cơ
    demo Bạn vào site và kéo thanh trượt xuống sẽ thấy hiệu ứng của nó. Thường nó viết bằng CSS mà dùng FireBug không ra được.
    Nên mình nghĩ là dùng Jquery.
     
  3. davidhuynhvan

    davidhuynhvan Member

    Bài viết:
    116
    Likes :
    22
    Đã tìm ra Code Jquery
    http://www.backslash.gr/content/blog/webdevelopment/6-navigation-menu-that-stays-on-top-with-jquery
    Thêm đoạn sau vào Header sữa navcontainer thành class CSS tương ứng.
    Mã:
    <script>
    $(function() {
    
        // grab the initial top offset of the navcontainer
        var navcontainer_offset_top = $('#navcontainer').offset().top;
     
        // our function that decides weather the navcontainer bar should have "fixed" css position or not.
        var navcontainer = function(){
            var scroll_top = $(window).scrollTop(); // our current vertical position from the top
         
            // if we've scrolled more than the navcontainer, change its position to fixed to stick to top, otherwise change it back to relative
            if (scroll_top > navcontainer_offset_top) {
                $('#navcontainer').css({ 'position': 'fixed', 'top':0, 'left':0,'opacity': 0.8 })
            } else {
                $('#navcontainer').css({ 'position': 'relative','opacity': 1 });
            }
        };
     
        // run our function on load
        navcontainer();
     
        // and run it again every time you scroll
        $(window).scroll(function() {
            navcontainer();
        });
     
        // NOT required:
        // for this demo disable all links that point to "#"
        $('a[href="#"]').click(function(event){
            event.preventDefault();
        });
     
    });
    </script>
     
    Last edited: 11/10/13
comments powered by Disqus

Chia sẻ trang này

Đang tải...