JS-JQ Intelligent positioning of elements in page scrolling (top-other parts)

Source: Internet
Author: User

Read the premise: fully understand the div three ways of positioning: floating, relative positioning, absolute positioning

Method One (top)

Principle: Direct use of CSS control; disadvantage: incompatible ie6-;

implementation: position:fixed; top:0

Method Two (top)

Principle: Gets the height of the page being curled (LEN), copied to obj. STYLE. Top=len, shortcomings, the effect is not very smooth!

Realize:

var len=document.documentelement.scrolltop| | Document.body.scrollTop;

var Obj=document.document.getelementbyid ("id")

Obj.style.top=len

Method three (various parts)

This is on the Internet to find the JQ method, oneself also actually wrote once;

$.fn.smartfloat =function (){
var position =function (Element){
var top = element.position (). Top;
var pos = element.css ("Position");
$ (window). Scroll (function (){
var scrolls = $ (This). ScrollTop ();
if (Scrolls > top){
if (window. XMLHttpRequest){
ELEMENT.CSS ({
Position"Fixed",
Top0
}). addclass ("Shadow");
}Else{
ELEMENT.CSS ({
Top:scrolls
});
}
}Else{
ELEMENT.CSS ({
Position:pos,
Top:top
"shadow");             } 
              }; 
    return $ ( Span class= "Js__operator" >this). each (function ()  { 
        position ($ (this));                            
     }; 

Call

$(function(){ 
    $("#nav").smartFloat(); 
}); 

ps:边框加阴影的css代码;
  .shadow{-moz-box-shadow:1px  1px 2px rgba (0,< Span class= "Css__number" >0,0,. 2);  -webkit-box-shadow:1px 1px 2PX&NBSP;&NBSP; 
Rgba (0,0, 0,. 2)  box-shadow:1px 1px  2px rgba (0,0,0,. 2);}  
 

JS-JQ Intelligent positioning of elements in page scrolling (top-other parts)

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.