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

推荐订阅源

小众软件
小众软件
C
Check Point Blog
Vercel News
Vercel News
Y
Y Combinator Blog
G
Google Developers Blog
P
Proofpoint News Feed
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
L
LangChain Blog
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园_首页
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog

博客园 - point.deng

Pinax安装笔记 CuteEditor使用心得 asp.net 中的default button DIV+CSS实现圆角 欢迎使用我的控件 有用的SQL语句,更新中~ asp.net 实现多语言界面 关于WebService中SOAP扩展求助~~ - point.deng - 博客园 同一账号多次登录 WEB自定义控件小记 C# 使用HOOK 小记 视频转为flv和图片 Asp.net上传图片产生预览效果(转) asp.net2.0用户和角色管理 javascript 练习 Ajax示例 asp.net开发小技巧 Master Page主题以及皮肤的使用 ASP.NET 2.0网站快速导航
悬浮的购物车 - point.deng - 博客园
point.deng · 2008-05-14 · via 博客园 - point.deng

今天在项目中看到可能会用到这个东西,我做了个小例子,其原理就是把一个层(定位一定要是absolute),在页面滚动的时候,触发事件,改变这个层的位置。
一、定义这个层:
     <div id="div1" style="position: absolute; z-index: 10000; background-color: Red;
        width: 300px; height: 200px;">
        这是一个悬浮的层!
    </div>
二、定义改变层位置的方法:
      function scrolls()
    {
        div1.style.marginTop=document.documentElement.scrollTop+div1.clientHeight;              div1.style.marginLeft=document.documentElement.scrollLeft+document.body.clientWidth - div1.clientWidth;
    }
三、在滚动事件中调用方法:
 window.onscroll = function()
    {
        scrolls();
    }

四、在加载事件中调用方法:
 window.onload=function()
    {
        scrolls();
    }

我不是最强的,但我是最努力的!