Created
October 29, 2012 02:21
-
-
Save Megic/3971062 to your computer and use it in GitHub Desktop.
Jquery:float div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Float(elementId,postion,styleCss){ | |
| this.id = elementId; | |
| this.div = $("#"+this.id); | |
| this.scrollTop = 0; | |
| this.screenHeight = window.screen.height-window.screenTop; | |
| this.topPx = rePosition(postion,this); | |
| div.css({"position":"absolute","top":topPx+"px"}); | |
| if(arguments.length > 2) | |
| $.each(styleCss,function(i,n){ | |
| div.css(i,n); | |
| }); | |
| var scrollObj = $.browser.msie ? document.documentElement : document.body; | |
| var Expression = null; | |
| window.onscroll = function(){ | |
| this.scrollTop = scrollObj.scrollTop; | |
| this.topPx = rePosition(postion,this); | |
| div.stop(true).animate({"top":this.topPx},500); | |
| } | |
| } | |
| function rePosition(postion,obj){ | |
| switch(postion){ | |
| case "TOP": | |
| obj.topPx = obj.scrollTop; | |
| break; | |
| case "CENTER": | |
| obj.topPx = (obj.scrollTop + ( obj.screenHeight / 2)); | |
| break; | |
| case "BOTTOM": | |
| obj.topPx = obj.screenHeight + obj.scrollTop - div.height()-60; | |
| } | |
| return obj.topPx; | |
| } | |
| //var div = Float("test","CENTER",{"color":"red"}); //使用 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment