JQUERY Implementation window scrolling search box docking effect (similar to scrolling docking) _jquery

Source: Internet
Author: User
When the page needs to display more content, many of us use pagination method to solve.

And sometimes, the effect of pagination is very disgusting. The scroll bar is undoubtedly a simple and efficient way. And here, in view of the user experience, I used jquery to achieve a similar "scrolling docking" effect. So when we scroll down the content, the search box "hangs" at the top of the window.

The advantage of doing this is that when the user needs to filter the content again, you don't have to scroll up again, you can always enter a condition to search.

Here are my ideas for achieving this effect
First, design a hidden search box. The style of the hidden search box, the event, and the search box that has been displayed are the same.
Then set the location of the hidden search box "absolute".
Third, use jquery to determine if the scroll bar's scrolling distance makes the previously displayed search box invisible, display the hidden search box fixed at the top.

Here are some of the code for this effect:
Floating search Box HTML code: (The Search box displayed is the same as this one, except that the classes are different.) )
Copy Code code as follows:

<div id = "Flowsearchdiv" >
<table class= "Flowsearch" >
<tr>
&LT;TD class= "ConditionName" > Conditions one:</td>
&LT;TD class= "Condition" >
<asp:dropdownlist id= "DropFlowCondition1" cssclass= "Drop" runat= "Server" >
</asp:DropDownList>
</td>
&LT;TD class= "ConditionName" > Condition two:</td>
&LT;TD class= "Condition" >
<asp:dropdownlist id= "DroFlowCondition2" cssclass= "Drop" runat= "Server" >
</asp:DropDownList>
</td>
&LT;TD class= "ConditionName" > Conditions three:</td>
&LT;TD class= "Condition" >
<asp:dropdownlist id= "DropFlowCondition3" cssclass= "Drop" runat= "Server" >
</asp:DropDownList>
</td>
&LT;TD class= "ConditionName" >
<asp:button id= "Flowbtnsearch" cssclass= "btn" runat= "server" text= "query"/>
</td>
</tr>
</table>
</div>

Floating search Box page CSS: (Display the search box and this style to be the same, but do not set position fixed)
Copy Code code as follows:

/* Dropdown Box * *
. Drop
{
width:175px;
}
/* The form in the Floating search box * *
#flowsearchdiv table
{
Background-color: #484343;
Color:white;
border-top:2px solid white;
}
* * In the floating search box * *
#flowsearchdiv
{
Display:none;
Position:absolute;
left:217px;
}

jquery Code:
Copy Code code as follows:

Implement window scrolling, search box does not scroll
$ (function () {
$ (window). Scroll (function () {
var top = $ (this). ScrollTop ();
var Flowsearch = $ ("#flowsearchdiv");
if (top-36 < 0) {
Floating search box hide, fade in effect
FLOWSEARCH.CSS ("Display", "none");
} else {
FLOWSEARCH.CSS ("Display", "block");
top = top + 40;
Flowsearch.css ("Top", top);
}
});

});

Here basically our effect comes out. When we scroll down the scroll bar, the hidden search box is displayed if the original search box is outside the viewable range of the page. From the user's point of view, is the search box stopped at the top of the page, so the user experience is self-evident.
Effect Chart:

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.