简体   繁体   English

jQuery滚动动画不停留在DIV中

[英]JQuery scroll animation not sticking within DIV

I have an issue with a JQuery animation I've been trying to implement within my site. 我一直在尝试在自己的网站上实施JQuery动画,但遇到了问题。

The general idea is that I have a footer on my page divided into two TDs. 一般的想法是,我在页面上有一个页脚,分为两个TD。 Section 1 is an icon that changes depending on the message that is scrolling by in section two. 第1部分是根据第二部分中滚动显示的消息而变化的图标。

My HTML essentially looks like this: 我的HTML本质上是这样的:

<div id="footer">
    <div class="box-ticker round">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="height:60px;">
            <tr>
                <td style="width:12%;background:#6dc5ed;" align="center" valign="middle"><img id="image_scroll" /></td>
                <td style="width:88%;background:#9f88e2;padding;10px" class="biggest" valign="middle">
                    <div id="ticker"></div>
                </td>
            </tr>
        </table>
    </div>
</div>

My CODE to update this: 我的代码来更新此:

EDIT: The variable "html" is a poorly named array of JSON. 编辑:变量“ html”是一个名称不正确的JSON数组。 It contains the data which I'm populating. 它包含我正在填充的数据。 Eg: html[0] = {'title':'this is a message', 'icon':'icon.png'} 例如:html [0] = {'title':'this is a message','icon':'icon.png'}

$('#ticker').html("<span class='scrollingtext' id='scroll_text'></span>");
cur_index=0;
max_index=html.length;
$(document).ready(function() {
    $('.scrollingtext').bind('marquee', function() {
        if (cur_index >= max_index) { cur_index = 0; }
        obj = JSON.parse(html[cur_index]);
        $('#image_scroll').attr('src',"img/"+obj.icon);
        $('#scroll_text').html(obj.title);
        var scrolling_text = $('#scroll_text');
        var text_container = $('#ticker');
        var tw = scrolling_text.width();
        var ww = text_container.width();
        scrolling_text.css({ right: -tw });
        scrolling_text.animate({ right: ww }, 30000, 'linear', function() {
            cur_index++;
            scrolling_text.trigger('marquee');
        });
    }).trigger('marquee');
});

And finally my CSS: 最后是我的CSS:

.box-ticker{
    width:100%;
    height:56px;
    background:#d44d4d;
}    

.round { border-radius: 20px; }

.scrollingtext{
    position:absolute;
    vertical-align:middle;
    white-space:nowrap;
    font-family: 'AsapBold', Arial, sans-serif;font-weight:normal;
    font-size:30px;
    float: right;
    color:#FFFFFF;
}

The problem is that when the message scrolls across the screen it does not appear to be locked into the "ticker" DIV at all but just scrolls directly across the bottom of the page and appears to just ignore every DIV tag I have there. 问题是,当消息在屏幕上滚动时,它似乎根本没有被锁定在“股票行情” DIV中,而是直接在页面底部滚动,而似乎只是忽略了我在那里的每个DIV标签。 When I observe the object updating within the chrome console the HTML seems to be appearing in the correct place. 当我在chrome控制台中观察到对象更新时,HTML似乎出现在正确的位置。

There is also a weird issue with what seem to be trailing dots following the animation along. 还有一个奇怪的问题,就是动画之后似乎有尾随点。 This does not seem to happen within firefox. 这似乎没有发生在Firefox中。

Any suggestions would be greatly appreciated. 任何建议将不胜感激。

Thank you! 谢谢!

Okay found it. 好的,找到它了。 Your problem appears to be your CSS. 您的问题似乎是CSS。 See working example here 这里查看工作示例

Add this to your CSS 将此添加到您的CSS

#ticker{width:100%;overflow:hidden; display:block; }

.scrollingtext{
position:relative;
vertical-align:middle;
white-space:nowrap;
font-family: 'AsapBold', Arial, sans-serif;font-weight:normal;
font-size:30px;
float: right;
color:#FFFFFF;
}

Note: I had to make change to your html object to make it work with jsfiddle. 注意:我必须对您的html对象进行更改才能使其与jsfiddle一起使用。 You can ignore the js code if you have no problem with yours. 如果您的js代码没有问题,则可以忽略js代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM