简体   繁体   English

Javascript或jQuery文本颜色幻灯片效果?

[英]Javascript or jQuery text colour slide effect?

I'm trying to make a basic navigation, all the links are plain text and the current page is displayed by a different colour. 我正在尝试进行基本导航,所有链接均为纯文本,当前页面以不同的颜色显示。

How would I go about having that different colour 'slide' to the current hovered navigation item? 我该如何对当前悬停的导航项使用不同的颜色“幻灯片”?

For example: http://www.branded07.com/ Something like that but instead of the background of that link sliding, could I have the text colour slide? 例如: http: //www.branded07.com/类似的东西,但是可以使文字颜色滑动而不是该链接滑动的背景?

This is a tough one :) As I understand what you're trying to achieve is when you have a single word, for example the word COLOR , displayed in red, to first have the C to change color, then the O, then the L etc. and in such a rapid and continuous motion it'll seem like the next color is sliding from left to right. 这很困难:)据我了解,您要实现的目标是当您有一个单词(例如以红色显示的单词COLOR ,首先使C改变颜色,然后使O变色,然后使L等,并以这种快速且连续的运动,似乎下一个颜色从左向右滑动。 Am i right? 我对吗?

First of all, colors cannot be animated using jQuery core, but you can use the jQuery.color() plugin (check out https://github.com/jquery/jquery-color ). 首先,无法使用jQuery核心对颜色进行动画处理,但是可以使用jQuery.color()插件(请查看https://github.com/jquery/jquery-color )。 Using this plugin a possible approach would be to grab the text you are working on (the hovered menu-item), cut out each letter and animate them one-by-one, using a little timeout to animate it. 使用此插件,一种可能的方法是抓取您正在处理的文本(悬停的菜单项),剪切每个字母并对其进行动画处理,并使用一点超时对其进行动画处理。

I have built you a example at jsfiddle, check it out and customize it for your needs: http://jsfiddle.net/xhCa2/ 我在jsfiddle上为您构建了一个示例,对其进行检查并根据您的需求对其进行自定义: http : //jsfiddle.net/xhCa2/

You have to use jQuery UI (extension to toggleClass function): 您必须使用jQuery UI(扩展到toggleClass函数):

Html: HTML:

<div class="menu">
<span class="menu-item">Menu 1</span>
<span class="menu-item">Menu 2</span>
<span class="menu-item">Menu 3</span>
<span class="menu-item">Menu 4</span>
</div>

Css: CSS:

.menu-item
{
    color: black;
}

.menu-item-hover
{
    color: red;
}

Javascript: Javascript:

$(".menu-item").each(function() {
    $(this).hover(function() {
        $(this).toggleClass('menu-item-hover', 500);
    });
});

Demo: http://jsfiddle.net/nQ6Ze/ 演示: http//jsfiddle.net/nQ6Ze/

From what you have described I think you mean something like this? 根据您的描述,我认为您的意思是这样的? http://www.gmarwaha.com/blog/2007/08/23/lavalamp-for-jquery-lovers/ http://www.gmarwaha.com/blog/2007/08/23/lavalamp-for-jquery-lovers/

Or at least it might be a starting point 至少它可能是一个起点

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

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