页面动画 - 滚动文本

发布于 2024-12-17 21:23:25 字数 416 浏览 0 评论 0 原文

我想创建类似于以下站点链接的效果,其中文本显示在固定大小的文本框中,然后可滚动,但是我想使用与示例类似的图形设计风格,而不是使用标准 HTML 滚动条它。

我还希望页面永远不需要刷新,例如,当您单击不同的菜单标题时,它只会更改显示的内容,而不必重新加载页面。我知道这部分可以用 Javascript 完成,并且很清楚如何去做,但不知道第一部分从哪里开始。

该示例网站的所有动画均使用 Flash。不过,我想坚持使用服务器/客户端语言,例如 HTML/HTML5、Javascript/jquery、PHP

示例站点:

http://www.theoceancollective.com/main.html

I want to create a effect similar to the following site link, where the text is displayed in a fix sized text box that is then scrollable, however I want to use similar graphical design style as in example as opposed to using standard HTML scroll bar for it.

I also want the page never to need be refreshed, e.g. when you click on a different menu heading it just changes the content displayed, and does not have to reload the page. I know this part can be done with Javascript, and have a fair idea of how to go about it, but have no idea where to start on first part.

The example site uses Flash for all it's animation. However I want to stick to sever/client side languages, e.g. HTML/HTML5, Javascript/jquery, PHP

Example site:

http://www.theoceancollective.com/main.html

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

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

发布评论

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

评论(2

萌酱 2024-12-24 21:23:25

对于动画、Ajax 和 Javascript 来说,一个好的开始是使用像 jQuery 这样的库。您仍然可以使用带有真实网址的菜单,出于 SEO 原因,该菜单会转到正确的网址。但是当用户按下该按钮时,Javascript 将取消真正的请求并使用 Ajax 调用来获取内容。使用 jQuery 的小例子:

$(function(){
    $("#menu li a").click(function(e){
        e.preventDefault(); // Cancel the page change
        var _this = $(this);
        $.ajax({
            url : "/urltogetpagecontent.php",
            success : function(result)
            {
                // Put result in #content div
                $("#content").html(result);
                // Change page selected, the new LI will have the class selected and it will be removed from the other LI's within #menu
                _this.parent().addClass("selected").siblings().removeClass("selected")
            }
        });
    });
});

这样您仍然可以使用原始导航,但取消页面更改。这将在文档准备好时调用,并将绑定到#menu li aclick 事件。如果你想让内容具有固定的高度,你可以将你的CSS设置为#content,如下所示:

#content
{
    height: 600px;
    overflow: auto; /* Makes scrollbar when needed */
}

如果你想滑入和滑出你的内容。您必须包围一个 DIV,它将添加到您的#content 中。因此,结构将类似于:

<div id="content">
    <div class="page">
        // Default page
    </div>
    <div class="page">
        // Second page loaded
    </div>
</div>

成功函数将类似于:

success : function(result)
        {
            // Put result in #content div
            var result = $(result).hide();
            $("#content").append(result);
            $("#content page").slideUp(); // Slide old content up
            result.stop(true, false).slideDown(); // Slide new content down

            // Change page selected, the new LI will have the class selected and it will be removed from the other LI's within #menu
            _this.parent().addClass("selected").siblings().removeClass("selected")
        }

上面的示例使用(一些阅读内容):

  1. jQuery.ajax
  2. jQuery.siblings
  3. jQuery.addClass / jQuery.removeClass
  4. jQuery.slideDown / jQuery.slideUp

可能的改进:
此代码不使用任何缓存,当您第二次单击链接时,它会执行另一个 Ajax 请求。您可以通过为 .page 类提供一个链接到 #menu li a 的 ID 来改进这一点。

A good start for animations, Ajax and Javascript is to use a library like jQuery. You can still use the menu with real url's which go to the right url for SEO reasons. But when a user presses that button, Javascript will cancel the real request and use an Ajax call to get the content. Small example using jQuery:

$(function(){
    $("#menu li a").click(function(e){
        e.preventDefault(); // Cancel the page change
        var _this = $(this);
        $.ajax({
            url : "/urltogetpagecontent.php",
            success : function(result)
            {
                // Put result in #content div
                $("#content").html(result);
                // Change page selected, the new LI will have the class selected and it will be removed from the other LI's within #menu
                _this.parent().addClass("selected").siblings().removeClass("selected")
            }
        });
    });
});

This way you can still use the original Navigation but cancel the pagechange. This will be called on document ready and will be bound to the click event of the #menu li a. If you want to have content with a fixed height, you can put your CSS as the #content as follow:

#content
{
    height: 600px;
    overflow: auto; /* Makes scrollbar when needed */
}

If you want to slide in and slide out your content. You have to got a DIV surrounded which will be added to you #content. So the structure will be something like:

<div id="content">
    <div class="page">
        // Default page
    </div>
    <div class="page">
        // Second page loaded
    </div>
</div>

And the success function will look something like:

success : function(result)
        {
            // Put result in #content div
            var result = $(result).hide();
            $("#content").append(result);
            $("#content page").slideUp(); // Slide old content up
            result.stop(true, false).slideDown(); // Slide new content down

            // Change page selected, the new LI will have the class selected and it will be removed from the other LI's within #menu
            _this.parent().addClass("selected").siblings().removeClass("selected")
        }

Above example uses (some read stuff):

  1. jQuery.ajax
  2. jQuery.siblings
  3. jQuery.addClass / jQuery.removeClass
  4. jQuery.slideDown / jQuery.slideUp

Possible improvements:
This code does not use any caching, sow when you click a link a second time, it does another Ajax request. You can improve this by giving the .page classes an ID which is linked to a #menu li a.

舞袖。长 2024-12-24 21:23:25
  1. 您可以使用 div 来保留所有文本内容,并在您的样式中指定固定高度和 Overflow:auto,您将根据文本内容高度自动滚动,并使用一些脚本来应用/制作精美的滚动条。

  2. Jquery 是无需加载/刷新页面即可获取内容的最佳选择。每次点击标题链接都会使用 Jquery.load 加载其他页面内容并加载主体/div 内容

  1. you can use div to keep all your text content and give fixed height and overflow:auto in your style, you will get scroll automatically according to your text content height and use some script to apply / make fancy scroll bar.

  2. Jquery is the best option to bring your content without loading/refresh the page. Each click of your header link use Jquery.load to load your other page content and load in main body/div content

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