我想创建类似于以下站点链接的效果,其中文本显示在固定大小的文本框中,然后可滚动,但是我想使用与示例类似的图形设计风格,而不是使用标准 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
发布评论
评论(2)
对于动画、Ajax 和 Javascript 来说,一个好的开始是使用像 jQuery 这样的库。您仍然可以使用带有真实网址的菜单,出于 SEO 原因,该菜单会转到正确的网址。但是当用户按下该按钮时,Javascript 将取消真正的请求并使用 Ajax 调用来获取内容。使用 jQuery 的小例子:
这样您仍然可以使用原始导航,但取消页面更改。这将在文档准备好时调用,并将绑定到
#menu li a
的click
事件。如果你想让内容具有固定的高度,你可以将你的CSS设置为#content
,如下所示:如果你想滑入和滑出你的内容。您必须包围一个 DIV,它将添加到您的
#content
中。因此,结构将类似于:成功函数将类似于:
上面的示例使用(一些阅读内容):
可能的改进:
此代码不使用任何缓存,当您第二次单击链接时,它会执行另一个 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:
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: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:And the success function will look something like:
Above example uses (some read stuff):
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
.您可以使用 div 来保留所有文本内容,并在您的样式中指定固定高度和 Overflow:auto,您将根据文本内容高度自动滚动,并使用一些脚本来应用/制作精美的滚动条。
Jquery 是无需加载/刷新页面即可获取内容的最佳选择。每次点击标题链接都会使用 Jquery.load 加载其他页面内容并加载主体/div 内容
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.
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