Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
利用js实现图片固定在屏幕的某个位置!_创想鸟

利用js实现图片固定在屏幕的某个位置!

利用js获取滚动条滚动距离,实现图片固定在屏幕的某个位置

思路:
1.获取对象距离顶部和左侧的距离;
2.获取元素对象;
3.当滚动条滚动时获取滚动条滚动的距离;
4.滚动条滚动时执行函数:对象距离顶部 / 左侧的距离变为原本距离顶部 / 左侧的距离+滚动条滚动像素数。

html代码:

            
利用js实现图片固定在屏幕的某个位置!

css代码:

*{            margin: 0;            padding: 0;        }        body{            width: 2000px;            height: 2000px;        }        .left{            position: absolute;            width: 110px;            height: 110px;            top: 100px;            left: 50px;        }        .right{            position: absolute;            width: 110px;            height: 110px;            top: 100px;            left: 1360px;        }

js代码:

存了个图 存了个图

视频图片解析/字幕/剪辑,视频高清保存/图片源图提取

存了个图 17 查看详情 存了个图

 var leftT;//左侧p距离顶部距离        var leftL;//左侧p距离左侧距离        var rightT;//右侧p距离顶部距离        var rightL;//右侧p距离左侧距离        var objLeft;//左侧p文档对象        var objRight;//右侧p文档对象        function place(){            objLeft=document.getElementById("left");            objRight=document.getElementById("right");            leftT=document.defaultView.getComputedStyle(objLeft,null).top;            leftL=document.defaultView.getComputedStyle(objLeft,null).left;            rightT=document.defaultView.getComputedStyle(objRight,null).top;            rightL=document.defaultView.getComputedStyle(objRight,null).left;        }        //获取滚动条滚动的像素数        function move(){            var scrollT=document.documentElement.scrollTop;            var scrollL=document.documentElement.scrollLeft;            //设置左侧p距离顶部的像素            objLeft.style.top=parseInt(leftT)+scrollT+"px";            objLeft.style.left=parseInt(leftL)+scrollL+"px";            objRight.style.top=parseInt(rightT)+scrollT+"px";            objRight.style.left=parseInt(rightL)+scrollL+"px";        }        window.onload=place;        window.onscroll=move;

相关推荐:【JavaScript视频教程】

以上就是利用js实现图片固定在屏幕的某个位置!的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/547080.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
探索电脑屏幕图案:设计、用途与影响
上一篇 2025年11月9日 18:14:23
java中string怎么比较
下一篇 2025年11月9日 18:14:36

相关推荐

发表回复

登录后才能评论
关注微信