Using jquery to transform the position of the search box

Source: Internet
Author: User

Now a lot of sites have such an effect: when the user searches for information, scrolling content, the position of the search box will change, will be fixed in a location, convenient for users to search again. such as Baidu Pictures. In order to improve the user experience of the system, but also want to join this effect, after a small period of time groping, the basic realization. Code is relatively simple, mainly CSS JS control. Specific as follows

1.css

Part, mainly set two styles, scroll before, after scrolling.

/* */.fossilinfohead{width:40% before rolling    ;    border-radius:2px;       min-width:500px;} /* After scrolling, the search box position */.fossilinfoheadnew {    position:fixed;   top:3px;    z-index:5001;    Background-color: #F5F5F5;}

  

2.js section. The main is to control good CSS

The use of both styles. The code is as follows:

/* Set the position of the search box */        $ (' #fossilInfoContainer ') when the picture is scrolled. Unbind (' scroll '). Bind (' scroll ', function () {            var scrolltop = $ (this). ScrollTop ();            var target = $ ('. Fossilinfohead ');            if (scrolltop >=) {                target.addclass (' fossilinfoheadnew '). CSS (' right ', ' 72px ');            } else {                Target.removeclass (' fossilinfoheadnew ');            }        );

The main code is such a few, but do not know whether Baidu is so realized, we can study under.

Using jquery to transform the position of the search box

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.