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

推荐订阅源

N
Netflix TechBlog - Medium
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
博客园 - Franky
F
Fortinet All Blogs
D
Docker
博客园 - 司徒正美
腾讯CDC
Recent Announcements
Recent Announcements
The Cloudflare Blog
B
Blog RSS Feed
GbyAI
GbyAI
T
Tailwind CSS Blog
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志

博客园 - 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();
    }

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