How to use JavaScript to quickly create a common type of navigation component: Sidebar

Source: Internet
Author: User

This article tags : JavaScript tips javascript javascript functions JavaScript processing sidebar javascript navigation components

Sidebar is a common type of navigation component that pops up from the page flanking to cover the normal content.

Let's say your normal content is:

    <div id="main">         Placeholder<p>         Placeholder<p> Placeholder<p> </div>

Now we can add sidebarto the content. It has links to home and about. and add a button, you can open sidebar, the code is as follows:

    <divId="Mysidenav"class="Sidebar" ><ahref="Javascript:void (0)"class="Closebtn"onclick="Closenav ()" >&times;</a><ahref="#a" >home</a><ahref="#b" >about</a></div><buttononclick="Opennav ()" >open Sidebar</button><p><divId="Main" > Placeholder<p> Placeholder<p> Placeholder<p></div><style>. Sidebar {Height100%;Width0;position:fixed;Z-index:1;Top0;Left0;Background-color:#111;Overflow-x: Hidden;Padding-top:60px;Transition0.5s; }. SidebarAPadding4px4px4px32px;Text-decoration:none;Color#818181;Display:block;Transition0.3s}. Sidebara:hover{ color: #f1f1f1;}. Sidebar. closebtn { position:absolute; top: 10px; Right : 10px;} </style> <script> function opennav () { document.getElementById ("Mysidenav" ). Style.width = "150px";} function Closenav () { document.getElementById ("Mysidenav"). Style.width = "0";} </script>                

The point is:

    1. By default, sidebar is a div built into any HTML, and width is 0, so it is not visible

    2. When you need to use sidebar, you can use a function to set its width to a wide, so it becomes visible

    3. Although it becomes visible, but because Z-index is 1, it does not cause the primary content to be re-rendered and the new location to be computed, but to overwrite the

      written in the end :forFreedom look outside the world, and it this line, not to go to Google data, finally, Amway a V--PN agent. a red apricot VPN, to Google to check the information is the absolute first choice, the connection speed, the use is also convenient. I bought is 99¥ a year, through this link (http://my.yizhihongxing.com/aff.php?aff=2509) registered after the Member center to lose the coupon code, split down, only 7 yuan per month, special benefits.

      This article tags : JavaScript tips javascript javascript functions JavaScript processing sidebar javascript navigation components

      Turn from SUN's BLOG-focus on Internet knowledge, share the spirit of the Internet!

      Original Address: " How to use JavaScript to quickly create a common type of navigation component: Sidebar"

      related reading:"Aaron swartz– Internet Genius to open the life course: every moment asked himself, now the world what is the most important thing I can participate in doing?" "
      Related reading: " site environment Apache + PHP + mysql xampp, how to implement a server on the configuration of multiple sites?" "

      Related reading: What is the engineer culture? Why are the engineers alive? Why do I need an engineer culture as an IT or internet company? "

      Related reading: useful for programmers: 2017 latest in Google's Hosts file download and summary of the various hosts encountered the problem of the solution and configuration of the detailed

      related reading: the Win10 perpetual activation tutorial and how can I see if the Windows system is permanently activated? 》

      Related blog:SUN ' S blog -Focus on Internet knowledge and share the spirit of Internet! Go and see:www.whosmall.com

How to use JavaScript to quickly create a common type of navigation component: Sidebar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.