惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
C
Cisco Blogs
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
I
InfoQ
GbyAI
GbyAI
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
TaoSecurity Blog
TaoSecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
月光博客
月光博客
W
WeLiveSecurity
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Security Latest
Security Latest
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
T
Troy Hunt's Blog
Martin Fowler
Martin Fowler
The Hacker News
The Hacker News
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
Stack Overflow Blog
Stack Overflow Blog
K
Kaspersky official blog
Cloudbric
Cloudbric
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog

博客园 - helloworld22

An excellent mockup tool -- Balsamiq Impression of Team Foundation Server 2010 Impression Of Book – Beautiful Architecture (翻译)十分钟内安装,配置,使用Windows Server AppFabric some useful links for dealing with blg file and performance analyses The time zones of Event log 用证书实现windows 2003下IIS的SSL安全通信 5 Whys Quickly Getting to the Root of a Problem Outlook 2007 Conflicts With Google Desktop Encourage Sentences Collections 标准Singleton设计模式,多线程下 kill all user in a database, very useful Be careful when you compare the GUID with a string Jmail 64bit 64位 不支持 machineKey - helloworld22 - 博客园 Error Install MS SQL Server Express in Windows XP SP3 / MSXML6 SP2 Sql 2005 Database diagram support objects cannot be installed because this database does not have a valid owner An error occurred during the execution of xp_cmdshell. A call to 'LogonUserW' failed with error code: '1385' Page Load called twice With FireFox - helloworld22
jQuery插件floatIt,浮动div并居中在上方或者下方 - helloworld22 - 博客园
helloworld22 · 2010-07-09 · via 博客园 - helloworld22
网上找的太重量级了,写了个轻量级的。满足自己的需求就好,以后再加各种浮动,比如右下角之类的。
/*
 * jQuery float it plugin
 * Version 1.0 (8-July-2010)
 * @requires jQuery v1.4 or later
 *
 * Copyright (c) 2009-2010 Tony ZHOU
 * Dual licensed under the MIT and GPL licenses:
 */
 
jQuery.fn.floatIt = function (options) {
    //parameter like { location: "bottom" } or { location: "top" }
    // by extending the default settings, we don't modify the argument
    settings = jQuery.extend({ location: "bottom" }, options);

    var h = $(window).height();
    var w = $(window).width();

    var topLocation = 0;
    var leftLocation = w / 2 - $(this).width()/2;

    var currentId = $(this).attr("id");

    switch (settings["location"].toLowerCase()) {
        case ("bottom"):
            topLocation = h - $(this).width();
            $(window).scroll(function () {
                var topLocation = $(document).scrollTop() + $(window).height() - $("#" + currentId).height(); //closure
                $("#" + currentId).css({ position: "absolute", top: topLocation, left: leftLocation });
            });
            break;
        case ("top"):
            topLocation = 0;
            $(window).scroll(function () {
                var topLocation = $(document).scrollTop(); //closure
                $("#" + currentId).css({ position: "absolute", top: topLocation, left: leftLocation });
            });
            break;
        default:
            topLocation = h - $(this).width();
            break;
    }

    $(this).css({ position: "absolute", top: topLocation, left: leftLocation });
};

用起来的时候直接$("divname").floatIt(),默认是bottom.

效果就是这样

要完整例子的话请移步到 http://www.iamtonyzhou.com/javascript/jquery-plugin-float-div-on-the-top-or-bottom-and-keep-it-in-the-center/

点击下图的链接下载