简体   繁体   English

如何自动滚动一个包含纯文本的div(水平)?

[英]How do you automatically scroll a div (Horizontally) which contains plain text?

Please bear with me here! 请在这里忍受我! I familiarized myself with basic HTML and decided web programming would be my occupation. 我熟悉基本的HTML,因此决定要进行网络编程。 I enrolled in a program and am now writing my first live project in my fourth semester. 我注册了一个程序,现在正在第四学期写我的第一个实时项目。 Our classes deal mainly in the .NET Framework and I am very unfamiliar with Javascript and client-side programming in general. 我们的类主要在.NET Framework中处理,而我一般对Javascript和客户端编程都不熟悉。

Hopefully I outline this information enough to give the great members of this community a chance to help a budding developer. 希望我对这些信息进行了概述,以使该社区的优秀成员有机会帮助一个崭新的开发人员。

Objective: Scroll a div containing plain text horizontally across a page indefinitely Environment: Windows server running ASP.NET 4.0. 目标:无限滚动整个页面上水平包含纯文本的div环境:运行ASP.NET 4.0的Windows服务器。 Language: C#/XHTML/Javascript Tools Used: jQuery, jQueryTools, SmoothDivScroll 语言:使用的C#/ XHTML / Javascript工具:jQuery,jQueryTools,SmoothDivScroll

I have attempted to use a jQuery plugin known as SmoothDivScroll as well as jQueryTools to execute my objective, however, with my lack of client-side experience, I have had absolutely no success. 我试图使用称为SmoothDivScroll的jQuery插件以及jQueryTools来执行我的目标,但是,由于缺乏客户端方面的经验,我绝对没有成功。

My webpage is available at http://paysonfirstassembly.com/ and the div that I am attempting to scroll has a class and ID of scrollingPanel. 我的网页可从http://paysonfirstassembly.com/获得,我尝试滚动的div的类和ID为scrollingPanel。

I can provide sample code if it will help. 如果有帮助,我可以提供示例代码。

-Taylor -Taylor

This seems to fit your needs: http://plugins.jquery.com/project/jqScroller 这似乎符合您的需求: http : //plugins.jquery.com/project/jqScroller

<style type="text/css">

  /* CSS for the scrollers */
  #scrollingPanel{
    position:relative;
    height:24px;
    width:500px;
    display:block;
    overflow:hidden;
    border:#CCCCCC 1px solid;
  }

  .scrollingtext{
      position:absolute;
      white-space:nowrap;
  }
</style>

$(document).ready(function() {

    //create a horizontal scroller
    $('#scrollingPanel').SetScroller({
        velocity: 80,
        direction: 'horizontal'
        //more tweaks on the source code of plugin page
    });


});

your HTML should be like this: 您的HTML应该是这样的:

<div id="scrollingPanel">
    <div class="scrollingtext">
        Making a Difference in People
    </div>
</div>

See this page source code for more functions and tweaks 请参阅此页面源代码以获取更多功能和调整

Remy Sharp has a good jQuery Marquee implementation here with some demos . Remy Sharp 在这里有一个不错的jQuery Marquee实现并带有一些演示 This allows you to do 这可以让你做

<div class='marquee'>Scroll this</div>

and then 接着

$('.marquee').marquee();

with his plug-in included. 包括他的插件。

Wrap your text in marquee tag like this 像这样将文字包裹在字幕标签中

<div class="scrollingPanel">
    <marquee>Making a Difference in People</marquee>
</div>

Though, I personally DO NOT RECOMMEND this solution. 不过,我个人不建议使用此解决方案。 But it will work for your college project like charm. 但是它会像魅力一样适用于您的大学项目。 It doesn't need any external scripts. 它不需要任何外部脚本。

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

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