20th rounds of Bootstrap3.0 Learning (JavaScript plug-in-rolling listening)

Source: Internet
Author: User
Tags rounds

Before reading, you can also go to the Bootstrap3.0 getting started learning series navigation to view the http://www.cnblogs.com/aehyok/p/3404867.html

This article mainly describes the JavaScript plug-in-drop menu.

Case

The scroll listening plug-in can automatically update the corresponding navigation tag based on the position of the scroll bar. You can scroll through this page to see the changes in the left navigation bar.

First, you can test the code to see the effect.

Content => <! -- Bootstrap --> <link href = rel = media => <! -- [Lt IE]> <script src => </script> <! [Endif] --> <style type =>-</style> After running, you can see the effect under the content, that is, where the scroll bar scroll the mouse gear.

Usage 1 -- data attributes

To listen<body>) But added to the Div above, you can see the code by yourself. Then add attributes to the divdata-spy="scroll"You can easily add the scroll listening function for the top navigation bar. Then adddata-targetAttribute. The value of this attribute is in any Bootstrap..navThe ID or class of the parent element of the component.

<div data-offset= = data-spy= data-target=></div>
The navigation link address must have a corresponding target.

The link address in the navigation bar must have the same ID value for the corresponding page element. For example,<a href="#home">home</a>Must correspond<div id="home"></div>.

Usage 2 -- use JavaScript

Start the scroll listener using JavaScript:

    <script type=>).scrollspy({ target:</script>

Remove the data-target attribute of the div whose style class is scrollspy-example. In this way, you can switch the scroll wheel.

Method. scrollspy ('refresh ')

When using the rolling listening plug-in, you need to call this method whenever you add or delete page elements from the DOM in the page, as follows:

$( $spy = $().scrollspy(

However, it is useless for the moment.

Option

Options can be passed through the data attribute or JavaScript. For the data attribute, you need to put the option name indata-For exampledata-offset="".

Event

 <script type=>).on(</script>

Note: you must add a scroll bar to the content of the rolling listener, that is, you must add a style in advance.

     <style type=>-</style>

Give the Div content a certain height.

After a long tangle, it is because there is no scroll bar for the content. Please remember this 1.1.

This article has been updated to the Bootstrap3.0 getting started learning series navigation http://www.cnblogs.com/aehyok/p/3404867.html

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.