常用Js代码库

1# jQuery实现在鼠标滚动后导航栏保持固定

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <style type="text/css"> 
  html,body,div,ul,li,ol,h1,h2,h3,h4,h5,h6,span,input{
    margin:0;padding:0;
  }
  .fixed {
      position: fixed;
      top: 0;
      width: 100%;
      margin: 0 auto;
      left: 0;
      z-index: 10000;
      background: pink;
  }
  </style>
</head>
<body style="height: 2000px">
  <div>sadadasd</div>
  <div class="header-bottom">    
    <div class="top-nav">
      <ul>
        <li><a href="home" class="scroll" >首页</a></li>
        <li><a href="about" class="scroll">关于我们</a></li>
        <li><a href="services" class="scroll">服务领域</a></li>
        <li><a href="project" class="scroll">业务案例</a></li>
        <li><a href="references" class="scroll">合作伙伴</a></li>
        <li><a href="activities" class="scroll">官方活动</a></li>
        <li><a href="news" class="scroll">新闻资讯</a></li>
        <li><a href="contact" class="scroll">联系我们</a></li>
      </ul>
    </div>
 </div>
 <script src="http://code.jquery.com/jquery-latest.js"></script>
 <script>
  $(document).ready(function() {
    var navOffset = $(".header-bottom").offset().top;
      $(window).scroll(function(){
          var scrollPos = $(window).scrollTop();
          if(scrollPos >= navOffset){
              $(".header-bottom").addClass("fixed");
          }else{
              $(".header-bottom").removeClass("fixed");
          }
    });

  });
</script>
</body>
</html>

2#overlay

css:

.lightboxOverlay {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
    background-color: #000;
    opacity: .8;
    display: none;
}
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.4;
    background: #000;
}

Jq:

        $hamburger.on('click', function() {
            $menu_mobile.addClass('active');
            $menu_mobile.hasClass('slide-in') ? $menu_mobile.removeClass('slide-in').addClass('slide-out') : $menu_mobile.removeClass('slide-out').addClass('slide-in');
            var $overlay = $('.fullscreen-overlay');
            var $body = $('body');
            $overlay.css('display', '');
            if($overlay.length <= 0) {
                $body.append('<div class="fullscreen-overlay"></div>');
                $overlay = $('.fullscreen-overlay');
            }
            if($menu_mobile.hasClass('slide-out')) {
                $overlay.css('display', 'none');
            }
            $overlay.on('click', function() {
                $(this).css('display', 'none');
                $menu_mobile.removeClass('slide-in').addClass('slide-out');
            });
        });

3 # jQuery实现显示隐藏加动画

2018-07-10 at 2.17 pm.gif

html

<div class="posting-tips open">
    <div class="tips-title">
        Posting Tips
        <span class="tips-icon"></span>
    </div>
    <div class="tips-message">
        <p>
            <span>Subject matters.</span> Keep it brief, clear and concise. Your subject is the only part of the message that shows in preview posts, so make it count.
        </p>
        <p>
            <span>Don't get too personal.</span> This is a public forum, so don't share any personal info. See our house rules for more information.
        </p>
        <p>
            <span>Stay on topic.</span> Include all relevant details in the body, and ask open-ended questions to encourage replies.
        </p>
    </div>
</div>

jquery:

;(function($){
    'use strict';
    $(function(){
        var $post_tips = $('.posting-tips');
        var $tips_icon = $post_tips.find('.tips-icon');
        var $tips_message = $post_tips.find('.tips-message');

        $tips_icon.on('click', function () {
            $tips_message.slideToggle();
            if ($post_tips.hasClass('open')) {
                $post_tips.removeClass('open');
            }else {
                $post_tips.addClass('open');
            }
        });
    });

})(LITHIUM.jQuery);
2018-07-10 at 2.20 pm.gif

html和jquery:

<div class="new-to-community">
    <h2>
        Welcome to Your Community
    </h2>
    <p>
        Hi everyone,
    </p>
    <p>
        Welcome to the AGL Community, a delicated online space to share, discuss, and learn about all things energy-related.
    </p>
    <p>
        This community has been built by you, for you. Information, advice, ideas, and answers are just a few clicks away.
    </p>
</div>

<div class="accordion-item-list">
    <ul>
        <li class="item">
            <h3 class="title">
                Community Basics
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        Our Community provide a place for members or participants to search for information, read and post about topics of interest, learn from each other share tips and experiences, and discuss topics like renewables, energy technulogy etc.
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                Need immediate, specific account/billing assistance?
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        While we want to help you effectively manage your energy, the Community is not suited to handle 1:1 service enquiries. To help with account and billing questions where you need to share sensitive information (i.e. your account and personal details), please contact us on <a href="http://aglener.gy/ChatFb">Facebook Messenger, chat</a> or call us 24/7 on <a href="tel:131245">131 245</a>.
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                Why register and become a member?
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        Feel free to <a href="https://community.agl.com.au/t5/Discussion-Topics/ct-p/discussion">browse discussion topics</a> and our <a href="https://community.agl.com.au/t5/FAQs/tkb-p/Knowledge-Base">FAQs</a> for information and answers.
                    </p>
                    <p>
                        Registering lets you take full advantage of the community, enabling you to give likes, vote on ideas, interact with other community members, or set customisation preferences.
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                Sign up options
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        Already have an AGL My Account or the AGL app? Use this same email address or <a href="/plugins/custom/aglenergy/aglsso/sso_login_redirect?returnTo=https%3A%2F%2Fcommunity.agl.com.au%2Ft5%2FGetting-Started%2Fbd-p%2Fgetting_started">log in</a> details to easily access and start contributing on the Community.
                    </p>
                    <p>
                        Not a current AGL customer? Don't already have an AGL online account? That's ok too! Our community is for anyone interested in chatting energy. <a href="/plugins/custom/aglenergy/aglsso/sso_login_redirect?referer=https%3A%2F%2Fcommunity.uat.agl.com.au%2Ft5%2FGetting-Started-New%2Fbd-p%2Fgetting-started#register">Join</a> up simply using your name and email address.
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                How to get involved
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        1. &nbsp;&nbsp; Review our simple ‘<a href="https://community.agl.com.au/t5/Getting-Started/The-AGL-Community-guidelines/m-p/4#M1">house rules</a>’ to be followed by all of our community members. We want you to feel at all times that your thoughts and opinions matter and are respected.
                    </p>
                    <p>
                        2. &nbsp;&nbsp; <a href="https://community.agl.com.au/t5/forums/searchpage">Search the Community</a> for information
                    </p>
                    <p>
                        3. &nbsp;&nbsp; View our FAQs for <a href="https://community.agl.com.au/t5/Knowledge-Base/tkb-p/Knowledge-Base">answers</a> and information published by experts
                    </p>
                    <p>
                        4. &nbsp;&nbsp; <a href="https://community.agl.com.au/">Ask your own question</a> or <a href="https://community.agl.com.au/t5/Discussion-Topics/ct-p/discussion">join an existing discussion</a>.
                    </p>
                    <p>
                        5. &nbsp;&nbsp; Let someone know that you appreciate their contribution. You’ll find a thumbs up icon-switch at the bottom of each post to give them a ‘like’
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                How to write a great post
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        1. &nbsp;&nbsp; Make your <span>subject</span> clear and concise including relevant keywords. Your subject is the only part of the message that shows in discussion topic preview posts. Remember not to share any personal information.
                    </p>
                    <p>
                        2. &nbsp;&nbsp; To encourage replies, in the <span>body</span> include all relevant details, especially for technical topics and ask ended questions
                    </p>
                    <p>
                        3. &nbsp;&nbsp; Help others discover your post by adding <span>Tags</span>. These are related single keywords or phrases. Enter them in the ‘Message Tags’ field separated by a comma
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                Feedback is welcome!
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        We want to hear what you think of the Community site. Good or bad, we don't mind. Add your feedback or suggestion to our <a href="https://community.agl.com.au/t5/Ideas/ct-p/ideas">Ideas Board here</a>. Or, you can private message the Community Manager if you're more comfortable doing it that way.
                    </p>
                </div>
            </div>
        </li>
        <li class="item">
            <h3 class="title">
                Meet your AGL Community team
                <i class="icon-switch"></i>
            </h3>
            <div class="text">
                <div class="text-outspace">
                    <p>
                        Your Community Manager is me - Sam, better known by my screen name <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/2023">Samjy</a>. Our fabulous moderators are <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/3830">Jayden</a>, <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/1979">The RealDaveyG</a> and <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/1603">Jordanemm</a>.
                    </p>
                    <ul class="managers-list">
                        <li>
                            <div class="avatar">
                                <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/2023">
                                    <img src="https://nepep88636.i.lithium.com/t5/image/serverpage/avatar-name/people-06/avatar-theme/candy/avatar-collection/AGL_Community/avatar-display-size/profile/version/2?xdesc=1.0" alt="Samjy">
                                </a>
                            </div>
                            <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/2023" class="user-name">Samjy</a>
                        </li>
                        <li>
                            <div class="avatar">
                                <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/3830">
                                    <img src="https://nepep88636.i.lithium.com/t5/image/serverpage/avatar-name/people-21/avatar-theme/candy/avatar-collection/AGL_Community/avatar-display-size/profile/version/2?xdesc=1.0" alt="Jayden">
                                </a>
                            </div>
                            <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/3830" class="user-name">Jayden</a>
                        </li>
                        <li>
                            <div class="avatar">
                                <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/1979">
                                    <img src="https://nepep88636.i.lithium.com/t5/image/serverpage/avatar-name/people-19/avatar-theme/candy/avatar-collection/AGL_Community/avatar-display-size/profile/version/2?xdesc=1.0" alt="TheRealDaveyG">
                                </a>
                            </div>
                            <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/1979" class="user-name">TheRealDaveyG</a>
                        </li>
                        <li>
                            <div class="avatar">
                                <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/1603">
                                    <img src="https://nepep88636.i.lithium.com/t5/image/serverpage/avatar-name/people-22/avatar-theme/candy/avatar-collection/AGL_Community/avatar-display-size/profile/version/2?xdesc=1.0" alt="Jordanemm">
                                </a>
                            </div>
                            <a href="https://community.agl.com.au/t5/user/viewprofilepage/user-id/1603" class="user-name">Jordanemm</a>
                        </li>
                    </ul>
                    <p>
                        If you have any queries or concerns, or just want to say hello, feel free to give us a shout!
                    </p>
                </div>
            </div>
        </li>
    </ul>
</div>

<@liaAddScript>
;(function($){
    'use strict';
    $(function(){
        function accordionClick() {
            var $accordionWrap = $('.accordion-item-list'); 
            var $switch = $accordionWrap.find('.icon-switch');
            $switch.on('click', function() {
                var $curItem = $(this).parent('.title').parent('.item');
                $curItem.hasClass('open') ? $curItem.removeClass('open') : $curItem.addClass('open');
                var $this_text = $(this).parent('.title').parent('.item').children('.text');
                $this_text.slideToggle();
            });
        }
        accordionClick();
    });
})(LITHIUM.jQuery);
</@liaAddScript>

1# jQuery实现头部,侧栏显示隐藏动画效果

.aside-pushy-right {
        opacity: 0;
    -webkit-transform: translate3d(100%, 0, 0);
    transform: translate3d(100%, 0, 0);
    transition: all 0.5s;
    &.open {
        opacity: 1;
        visibility: visible;
        transform: translate3d(0, 0, 0);
        z-index: 1000;
    }
}

用max-height代替display实现动画效果

max-height: 0;
transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
-webkit-transition: max-height 0.3s;
overflow: hidden;


max-height: 150px;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,194评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,058评论 2 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,780评论 0 346
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,388评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,430评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,764评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,907评论 3 406
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,679评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,122评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,459评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,605评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,270评论 4 329
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,867评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,734评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,961评论 1 265
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,297评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,472评论 2 348

推荐阅读更多精彩内容