WordPress Theme Sidebar Scroll with Window

WordPress ninety-nine 19.6K Reading mode
abstract It seems that this special effect is very popular at present, and a tutorial named "jQuery enables the sidebar to scroll with the window" has been published before. However, some children's shoes found that with this JS special effect, the sidebar will roll down endlessly against the footer, which is a perfect one. Modify

It seems that this special effect is very popular at present, and it has been published before JQuery Implement Sidebar Scroll with Window However, some children's shoes found that the side bar would roll down against the footer after adding the JS special effect, so they would send a more perfect code:

  1. <script type= "text/javascript" >
  2. var  documentHeight = 0;
  3. var  topPadding = 15;
  4. $( function () {
  5.      var  offset = $( "#sidebar" ).offset();
  6.     documentHeight = $(document).height();
  7.     $(window).scroll( function () {
  8.          var  sideBarHeight = $( "#sidebar" ).height();
  9.          if  ($(window).scrollTop() > offset.top) {
  10.              var  newPosition = ($(window).scrollTop() - offset.top) + topPadding;
  11.              var  maxPosition = documentHeight - (sideBarHeight + 368);
  12.              if  (newPosition > maxPosition) {
  13.                 newPosition = maxPosition;
  14.             }
  15.             $( "#sidebar" ).stop().animate({
  16.                 marginTop: newPosition
  17.             });
  18.         }  else  {
  19.             $( "#sidebar" ).stop().animate({
  20.                 marginTop: 0
  21.             });
  22.         };
  23.     });
  24. });
  25. </script>

Add the above javascript code to the theme header. php template.

Modify the #sidebar ”Side selector name for your theme;

Properly adjust the number according to the height of the header template of different themes three hundred and sixty-eight (The default number is HotNews topic).

Personally, I think that the side module is not very comfortable when the page is added with this special effect. It is suitable for the side bar with less content or the fixed module at the bottom of the side, such as advertisement scrolling. Each has his own love for turnips and vegetables. Let's continue to struggle.

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments ninety-nine    Visitors ninety    Author five
    •  Slight opening of eye curtain
      Slight opening of eye curtain five

      Hehe, the first sofa, Brother Bird hasn't been updated for a long time

      •  Slight opening of eye curtain
        Slight opening of eye curtain five

        There is dislocation when moving to the top

          •  Robin
            Robin

            @ Slight opening of eye curtain Hehe, just now I was just testing. It's a perfect rolling effect
            I haven't had much spare time recently, so I don't have time to bother

          •  Advocate Sprouting
            Advocate Sprouting three

            There is a version that does not wobble and is fixed

            •  Chinese IT Information Station
              Chinese IT Information Station three

              How to achieve the waterfall effect?

              •  Kailiu net
                Kailiu net zero

                http://kailiwuang.net
                Please go and have a look. Why is the page opened by my video image tag always misplaced??
                How to solve it??
                What's more, after the title below is removed from the horizontal scroll of the home video, the height becomes smaller?
                thank you

                •  A wall
                  A wall four

                  Wow, that's what I'm waiting for

                  •  A wall
                    A wall four

                    It's better than the original one, although there is a bug

                    •  Liu Yin's Blog
                      Liu Yin's Blog two

                      I don't like this effect. ha-ha

                      •  How about Packard
                        How about Packard one

                        Go back and test it to see if it works.

                        •  How about Qiaosha Eye Cream
                          How about Qiaosha Eye Cream one

                          Very good effect.

                          •  Popular women's bag
                            Popular women's bag zero

                            Just tried on the theme, and the effect is good, thank you

                            •  President of Cat Council
                              President of Cat Council two

                              Thank you, Brother Bird. But after using this new code, it still doesn't work. The bottom page is still bottomless. I also changed the number 368 to 0100200500900...
                              Ps: The question function of wopus seems to be invalid..

                              •  Guangzhou Moving Company
                                Guangzhou Moving Company one

                                Not bad, thanks for sharing.

                                •  Guangzhou Decoration
                                  Guangzhou Decoration one

                                  Hehe, come and step on it.

                                  •  Software box
                                    Software box two

                                    Sometimes this function is necessary

                                    •  Slobber
                                      Slobber zero

                                      This code is much better Thank you

                                      •  Skull Cat
                                        Skull Cat five

                                        Brother Bird, the most active readers on the sidebar are listed from top to bottom according to the number of comments, right? How can I change this to list by name and number? Now they are arranged by avatars. I looked for the sidebar and didn't see it. Thank you

                                        •  Win7en Paradise
                                          Win7en Paradise eight

                                          This is not really needed, hey! I haven't succeeded~~

                                          •  Sanshui
                                            Sanshui three

                                            Ask a question, why can't the picture be displayed

                                            •  Skull Cat
                                              Skull Cat five

                                              Brother Bird, why can't my inside sidebar gadget be displayed. Drag several tools to all pages. Dead or alive is not displayed..

                                              •  hello
                                                hello two

                                                How does wordpress add thumbnails to articles with custom columns?

                                                Hello, Brother Bird, please ask me a question. I use Brother Bird's template. When the template is explained to thumbnails, there is such a sentence: "Add a custom column, call the specified picture, and recommend this method."
                                                I want to ask
                                                1. How to add a user-defined column?
                                                2. How to use this method? How can I call a picture?

                                                The friends who know can also tell me, thank you!!

                                                  •  Robin
                                                    Robin

                                                    @ hello It has been written in the subject instructions

                                                      •  hello
                                                        hello two

                                                        @ Robin The "Add custom columns, it seems that the control panel does not have this option, where is the background operation?"?

                                                          •  Lonely wind
                                                            Lonely wind one

                                                            @ hello There is a display option in the upper right corner of the background where you write articles. Click it, check the custom column, and it will be available under the editing area!

                                                              •  hello
                                                                hello two

                                                                @ Lonely wind What is the value? For example, I want to specify that the article corresponds to a fixed image, and do not allow the image to be displayed immediately. How can I do this? thank you

                                                        •  hello
                                                          hello two

                                                          And where is the microblog and subscription of the small speaker at the bottom changed into its own?

                                                          •  wmtimes
                                                            wmtimes seven

                                                            The effect is good. It's been a long time. Your update is also slow.

                                                            •  forty-five million four hundred and fifty-four thousand five hundred and forty-six
                                                              forty-five million four hundred and fifty-four thousand five hundred and forty-six zero

                                                              Ha ha ha ha ha ha ha

                                                                •  hello
                                                                  hello two

                                                                  @ forty-five million four hundred and fifty-four thousand five hundred and forty-six Let me ask you a question. I use the template of Brother Bird. When the template is explained to the thumbnail, there is such a sentence: "Add a custom column, call the specified picture, and recommend this method."
                                                                  I want to ask
                                                                  1. How to add a user-defined column?
                                                                  2. How to use this method? How can I call a picture?
                                                                  If you know something, you can also tell me, thank you!!
                                                                  When adding a custom column, what is the value? For example, I want to specify that the article corresponds to a fixed image, and do not allow the image to be displayed immediately. How can I do this? thank you

                                                                •  Win7en Paradise
                                                                  Win7en Paradise eight

                                                                  Brother Bird, PR has been updated

                                                                  •  Youfa 058
                                                                    Youfa 058 zero

                                                                    Learned a good article

                                                                    •  eat with appetite
                                                                      eat with appetite one

                                                                      Learned, support Brother Bird

                                                                      •  Domestic oxygen generator
                                                                        Domestic oxygen generator zero

                                                                        I'm looking for this code, hehe

                                                                          •  hello
                                                                            hello two

                                                                            @ Domestic oxygen generator Let me ask you a question. I use the template of Brother Bird. When the template is explained to the thumbnail, there is such a sentence: "Add a custom column, call the specified picture, and recommend this method."
                                                                            I want to ask
                                                                            1. How to add a user-defined column?
                                                                            2. How to use this method? How can I call a picture?
                                                                            The friends who know can also tell me, thank you!!
                                                                            When adding a custom column, what is the value? For example, I want to specify that the article corresponds to a fixed image, and do not allow the image to be displayed immediately. How can I do this? thank you
                                                                            Submitted successfully, you can

                                                                          •  Sanshui
                                                                            Sanshui three

                                                                            ask a question
                                                                            Can you select only one link category to display the friendship links under the page?

                                                                              •  Robin
                                                                                Robin

                                                                                @ Sanshui This function has been reserved for the theme. Open the footer template to find "&category=" followed by the link category ID

                                                                                  •  Sanshui
                                                                                    Sanshui three

                                                                                    @ Robin Thank you very much. It's very helpful!
                                                                                    One more question, can you add nofollow to the friendship link

                                                                                      •  Robin
                                                                                        Robin

                                                                                        @ Sanshui Yes, the link editing page adds nofollow in the "link network" relationship (rel)

                                                                                          •  Sanshui
                                                                                            Sanshui three

                                                                                            @ Robin Brother, did you add rel="nofollow" to the "Remarks" below?
                                                                                            Relationship (rel), can't write anything, can only choose, colleagues, friends, etc. You can't write rel="nofollow" directly

                                                                                        •  Bob
                                                                                          Bob five

                                                                                          @ Robin Brother Bird is really careful!

                                                                                      •  Reducer
                                                                                        Reducer one

                                                                                        Good article.

                                                                                        •  Platform rental
                                                                                          Platform rental one

                                                                                          Yes, it is worth learning from.

                                                                                          •  Tmd
                                                                                            Tmd five

                                                                                            Not interested in this effect

                                                                                            •  Xi'an People's Hospital
                                                                                              Xi'an People's Hospital zero

                                                                                              It's a good backup

                                                                                              •  Xi'an People Flow
                                                                                                Xi'an People Flow zero

                                                                                                The effect is very good

                                                                                                •  things will develop in the opposite direction when they become extreme
                                                                                                  things will develop in the opposite direction when they become extreme two

                                                                                                  Brother Bird, can you share the "back to the top" code on your right.

                                                                                                  •  Tianxia Share Network
                                                                                                    Tianxia Share Network one

                                                                                                    Brother Bird, my website ID is too many, and the webpage cannot be displayed [img] http://www.ttshare.com/wp-admin/themes.php?page=theme_options.php [/img]

                                                                                                    •  DHA
                                                                                                      DHA one

                                                                                                      I have learned. It seems that I am still too young!

                                                                                                      •  Adazi Information Network
                                                                                                        Adazi Information Network three

                                                                                                        This,,, effect is beautiful~~

                                                                                                        •  Xingrui Computer Network
                                                                                                          Xingrui Computer Network zero

                                                                                                          This special effect is very good. I'll try it too

                                                                                                          •  Kute.com
                                                                                                            Kute.com one

                                                                                                            Radish and vegetables, each has his own love

                                                                                                            •  Taige
                                                                                                              Taige one

                                                                                                              The blogger has time to change the picture on the home page to auto scroll. I studied all night, but I didn't respond to the change. I don't know where I made a mistake.

                                                                                                              •  ئۇچقۇن
                                                                                                                ئۇچقۇن one

                                                                                                                Hello, I used your theme,, Thank you so much..
                                                                                                                This theme widget does not display the home page [img] http://uchqun.com/1.jpg [/img]
                                                                                                                [img] http://uchqun.com/2.jpg [/img]

                                                                                                                •  ئۇچقۇن
                                                                                                                  ئۇچقۇن one

                                                                                                                  Help me to correct it... Excuse me

                                                                                                                  •  Reducer
                                                                                                                    Reducer zero

                                                                                                                    Well, although the blogger said it was uncomfortable, it was really a good method, which might be convenient for some customers

                                                                                                                    •  Yiwu Recruitment Website
                                                                                                                      Yiwu Recruitment Website two

                                                                                                                      The code is incomprehensible, but it can be copied and used. Thank you.

                                                                                                                      •  Jason
                                                                                                                        Jason zero

                                                                                                                        If I want the bottom gadget on the right to follow the bottom of the page, instead of following the gadget on the top to the bottom. How to achieve? That is to say, sometimes the article is too long, and when it comes to the later part of the article, there will be no gadgets on the left, that is, the blank area. I want the bottom gadget on the left to follow, so there will be no blank area. How can I achieve this?

                                                                                                                          •  Robin
                                                                                                                            Robin

                                                                                                                            @ Jason It is impossible to just scroll the bottom widget, because you cannot select a widget DIV alone. The only way is to modify the template yourself, add a special fixed module on the side, and then select this module to scroll

                                                                                                                          •  Qinyuan Spring
                                                                                                                            Qinyuan Spring one

                                                                                                                            Yes, I have. I'm going to make a blog for myself. Many people use this topic.

                                                                                                                            •  Space 9
                                                                                                                              Space 9 two

                                                                                                                              About this function, I have to spit out the slot today. I started to struggle after I published a long article in the afternoon. I didn't realize the following and scrolling until one o'clock in the morning. Generally, the js code is placed between and tags, but it can't be realized by putting it between and. At first, I thought that my right side was too long, so it was invalid, so I went online to find it, I tried several codes, but none. During the period, I found that many of them were copied directly from Brother Bird, even the words outside the code were identical. Later I saw your previous article "jQuery Implementation Sidebar Scroll with Window"
                                                                                                                              》On the 28th floor, I went to his station to see the reply. There was a sentence "Step 2: Add the following code to the top template:". I wondered if it was because my code was placed in front that it was invalid. I immediately changed Brother Bird's code to, uploaded and refreshed it. Oh yeah, it took me eight or nine hours to get it right, but one code was misplaced... Ah... But with this effect, reading is really dazzling. http://www.xptt.com/to-roll-up-your-sidebar.html/comment-page-1 Brother Bird, like pulling out the popular tags and random articles separately on this page, and not following the scroll, but fixing them. How can we achieve this? The code released on this is also scrolled along the whole sidebar, which is different from the code used by him. I now use this on the website to test. Because our hotnews theme calls the backend widget set directly, how can we select the ID of one or several modules separately? I really can't think of a way out, so I have to consult you here.

                                                                                                                              •  xlxl2010
                                                                                                                                xlxl2010 one

                                                                                                                                I like this function

                                                                                                                                •  Bad egg box
                                                                                                                                  Bad egg box zero

                                                                                                                                  Can the sidebar be fixed and moved?

                                                                                                                                  •  celine outlet
                                                                                                                                    celine outlet one

                                                                                                                                    The sidebar can be fixed and moved

                                                                                                                                    •  Fresh discount code
                                                                                                                                      Fresh discount code three

                                                                                                                                      This is a little annoying

                                                                                                                                      •  mays1986
                                                                                                                                        mays1986 one

                                                                                                                                        I've been looking for such things

                                                                                                                                        •  Xiamen SEO
                                                                                                                                          Xiamen SEO zero

                                                                                                                                          It seems that you have to make trouble to make your blog more perfect. Try to achieve various special effects.

                                                                                                                                          •  nurbilik
                                                                                                                                            nurbilik zero

                                                                                                                                            How to change which code with header??

                                                                                                                                            •  Classical Dao
                                                                                                                                              Classical Dao zero

                                                                                                                                              What is the name of the selector on the theme side

                                                                                                                                              •  inphon
                                                                                                                                                inphon zero

                                                                                                                                                This is good, but you must use jquery.min.js
                                                                                                                                                It conflicts with some plug-ins that must use jquery.js in the fancy-box

                                                                                                                                                •  Susu Wangzhuan Blog
                                                                                                                                                  Susu Wangzhuan Blog two

                                                                                                                                                  I finally found it. Thank you for sharing

                                                                                                                                                  •  Read more than ten thousand volumes
                                                                                                                                                    Read more than ten thousand volumes zero

                                                                                                                                                    This function is not bad. It would be great if it could be written as a plug-in

                                                                                                                                                    •  Online earning blog
                                                                                                                                                      Online earning blog three

                                                                                                                                                      Thank you, Master Mockingbird

                                                                                                                                                      •  wheat berry
                                                                                                                                                        wheat berry zero

                                                                                                                                                        Try it first and learn from it. Is this the effect of your current sidebar?

                                                                                                                                                        •  Salon
                                                                                                                                                          Salon four

                                                                                                                                                          The article also said that the effect would be wobbly, but your website's sidebar doesn't follow the window. What's the reason?

                                                                                                                                                          •  Smart Internet
                                                                                                                                                            Smart Internet three

                                                                                                                                                            Can you help me see why I want the five icons on the right to follow me? It's like id=text-4

                                                                                                                                                            •  Fitness protective equipment
                                                                                                                                                              Fitness protective equipment zero

                                                                                                                                                              If the code is added, why not display it? Is it related to the theme.

                                                                                                                                                              •  tomato
                                                                                                                                                                tomato two

                                                                                                                                                                Strange, I just added this code to my blog, but it doesn't appear. Is it because the name of the sidebar selector is wrong? Continue to struggle

                                                                                                                                                                •  Shenzhen SEO
                                                                                                                                                                  Shenzhen SEO zero

                                                                                                                                                                  Isn't it similar to the nature of HTML5? However, it seems not conducive to SEO optimization.

                                                                                                                                                                  •  Ancient man
                                                                                                                                                                    Ancient man two

                                                                                                                                                                    [Name of the selector on the side of the theme] What is it? I haven't found it with firebug for a long time

                                                                                                                                                                    •  crazy
                                                                                                                                                                      crazy zero

                                                                                                                                                                      I used this code and found that it was slow, not the effect of your website. Please check it

                                                                                                                                                                      •  Beauty Care Net
                                                                                                                                                                        Beauty Care Net zero

                                                                                                                                                                         :mrgreen: Not bad

                                                                                                                                                                        •  Dark Blue
                                                                                                                                                                          Dark Blue zero

                                                                                                                                                                          Could you update how your current sidebar is implemented? thank you

                                                                                                                                                                            •  Cross border e-commerce platform
                                                                                                                                                                              Cross border e-commerce platform two

                                                                                                                                                                              @ Dark Blue Very good!!!!
                                                                                                                                                                              (The sidebar of the 299 yuan advertisement) It is fixed first, and then appears when it is pulled down.
                                                                                                                                                                              How is the current sidebar implemented?

                                                                                                                                                                            •  Populus euphratica
                                                                                                                                                                              Populus euphratica zero

                                                                                                                                                                              This code will still scroll against the bottom. Can't you stop scrolling at a certain position?

                                                                                                                                                                             anonymous

                                                                                                                                                                            Comment

                                                                                                                                                                            Anonymous netizens
                                                                                                                                                                             :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

                                                                                                                                                                            Drag the slider to complete validation