0

这是我想要实现的一些代码的链接。

http://jsfiddle.net/g7gYy/12/

我在确定代码的放置位置并使其实际工作时遇到了一些麻烦。

这是我上传的 html 文件:http: //www.canning.co.nz/Game/testmarquee.html

我可以帮忙吗?

谢谢

4

2 回答 2

1

首先,您没有将 jquery lib 添加到您的页面中添加它。

<script src="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

接下来将所有代码放入文档准备就绪,因为在文档准备就绪之前,您的代码已执行但元素尚未准备好执行某些操作

$(document).ready(function() {
    var $text = $('.text-to-scroll', $marquee);
    var textWidth = $text.width();

    var $marquee = $('#marquee');
    var marqueeWidth = $marquee.width();
    $marquee.css('height', $text.height());

    function animateLoop()
    {
        //First lets put if out of view to the left
        $text.css('left', -textWidth);
        //Now it's out of view, change it's display from none to block
        $text.css('display', 'block');

        //Now we can animate it so that if scrolls across the screen
        //http://api.jquery.com/animate/
        $text.animate({ 'left' : marqueeWidth }, 10000, 'linear', animateLoop);
    }
});
于 2012-04-06T12:50:46.000 回答
0

您的 javascript 文件链接不好。

<script language="JavaScript" type="text/javascript" src="marquee.js">

确保 marquee.js 文件与 testmarquee.html 页面位于同一文件夹中。

后期编辑:

哦,从头开始,我错了,Mateusz 实际上是对的。:D

于 2012-04-06T12:18:19.680 回答