WordPress 中的可滚动浮动图像

发布于 2024-12-05 14:33:47 字数 2014 浏览 1 评论 0原文

我想实现一个浮动图像,当用户滚动页面时它会向上/向下滚动。

我在 google 上搜索了一段在练习板上表现出色的代码,但是当我将其插入到我的 Wordpress footer.php 中(按照指示就在 end-body-tag 之前)时,它就放在那里并且当我滚动时不会滚动...

代码如下:

<script>

if (!document.layers)

document.write('<div id="divStayTopLeft" style="position:absolute">')

</script>

<layer id="divStayTopLeft">

<!--EDIT BELOW CODE TO YOUR OWN MENU-->

<a href="google.ca"><img src="http://nailian.ca/wp-content/uploads/misc/coupon.png"></a>

<!--END OF EDIT-->

</layer>


<script type="text/javascript">

//Enter "frombottom" or "fromtop"
var verticalpos="fromtop"

if (!document.layers)
document.write('</div>')

function JSFX_FloatTopDiv()

{

    var startX = 3,

    startY = 150;

    var ns = (navigator.appName.indexOf("Netscape") != -1);

    var d = document;

    function ml(id)

    {

        var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];

        if(d.layers)el.style=el;

        el.sP=function(x,y){this.style.left=x;this.style.top=y;};

        el.x = startX;

        if (verticalpos=="fromtop")

        el.y = startY;

        else{

        el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;

        el.y -= startY;

        }

        return el;

    }

    window.stayTopLeft=function()

    {

        if (verticalpos=="fromtop"){

        var pY = ns ? pageYOffset : document.body.scrollTop;

        ftlObj.y += (pY + startY - ftlObj.y)/8;

        }

        else{

        var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;

        ftlObj.y += (pY - startY - ftlObj.y)/8;

        }

        ftlObj.sP(ftlObj.x, ftlObj.y);

        setTimeout("stayTopLeft()", 10);

    }

    ftlObj = ml("divStayTopLeft");

    stayTopLeft();

}

JSFX_FloatTopDiv();

</script>

链接将位于此处: http://nailian.ca/

I want to implement a floating image that would scroll up/down when the user scrolls the page.

I googled up a code that works awesome in a practice board, but when I insert it (just right before the end-body-tag as instructed) in my Wordpress footer.php, it just sits there and won't scroll as I scroll...

The code is as follows:

<script>

if (!document.layers)

document.write('<div id="divStayTopLeft" style="position:absolute">')

</script>

<layer id="divStayTopLeft">

<!--EDIT BELOW CODE TO YOUR OWN MENU-->

<a href="google.ca"><img src="http://nailian.ca/wp-content/uploads/misc/coupon.png"></a>

<!--END OF EDIT-->

</layer>


<script type="text/javascript">

//Enter "frombottom" or "fromtop"
var verticalpos="fromtop"

if (!document.layers)
document.write('</div>')

function JSFX_FloatTopDiv()

{

    var startX = 3,

    startY = 150;

    var ns = (navigator.appName.indexOf("Netscape") != -1);

    var d = document;

    function ml(id)

    {

        var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];

        if(d.layers)el.style=el;

        el.sP=function(x,y){this.style.left=x;this.style.top=y;};

        el.x = startX;

        if (verticalpos=="fromtop")

        el.y = startY;

        else{

        el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;

        el.y -= startY;

        }

        return el;

    }

    window.stayTopLeft=function()

    {

        if (verticalpos=="fromtop"){

        var pY = ns ? pageYOffset : document.body.scrollTop;

        ftlObj.y += (pY + startY - ftlObj.y)/8;

        }

        else{

        var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;

        ftlObj.y += (pY - startY - ftlObj.y)/8;

        }

        ftlObj.sP(ftlObj.x, ftlObj.y);

        setTimeout("stayTopLeft()", 10);

    }

    ftlObj = ml("divStayTopLeft");

    stayTopLeft();

}

JSFX_FloatTopDiv();

</script>

A link would be here : http://nailian.ca/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-12-12 14:33:47

我认为 css 样式 position:fixed 正是您所需要的。

这是一个示例

I think the css style position: fixed is what you need here.

Here's an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文