作者是如何在文字中做出均衡器效果的?

发布于 2024-12-28 10:25:15 字数 223 浏览 2 评论 0原文

http://www.chris-wang.com/

如果您将鼠标悬停在此处的文本导航词上页面,您会看到它在文本内从左到右改变颜色。我不明白这个人是怎么做到的,甚至不知道他使用了什么技术来做到这一点。

他是用画布来做的吗?有谁知道这个效果是怎么做出来的吗?文本不是图像,而是可选择的文本。

http://www.chris-wang.com/

If you hover over the textual navigation words on this page, you'll see it changes color from left to right, inside the text. I can't figure out how this guy did that, or even what technology he used to do it.

Is he using canvas to do it? Does anyone know how he did this effect? The text isn't an image, it's selectable text.

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

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

发布评论

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

评论(2

澉约 2025-01-04 10:25:15

它是 javascript 和 jquery:

function onOver(){
        //var txtwidth = $(this).document.getElementsByClassName("nav_over").clientWidth;
        //var txtwidth = $(this).children(".nav_over").offsetWidth;
        var txtWidth = $(this).children(".project_header").children(".nav_btn").children(".nav_base").width();
        //var txtWidth = document.getElementByClass("nav_base").offsetWidth
        //var txtWidth = $(document).width();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width:txtWidth
        }, speed,"easeOutExpo");
    };
function onOut(){
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width: "0px"
        }, speed,"easeOutExpo");
};

本质上只是 2 个具有相同文本但两种不同颜色的 div。当鼠标悬停在上方时,橙色的动画会覆盖白色的动画。

It's javascript with jquery:

function onOver(){
        //var txtwidth = $(this).document.getElementsByClassName("nav_over").clientWidth;
        //var txtwidth = $(this).children(".nav_over").offsetWidth;
        var txtWidth = $(this).children(".project_header").children(".nav_btn").children(".nav_base").width();
        //var txtWidth = document.getElementByClass("nav_base").offsetWidth
        //var txtWidth = $(document).width();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width:txtWidth
        }, speed,"easeOutExpo");
    };
function onOut(){
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width: "0px"
        }, speed,"easeOutExpo");
};

Essentially just 2 divs with the same text but two different colors. When moused over, the orange one is animated to cover over the white one.

北座城市 2025-01-04 10:25:15

他使用 jQuery 来实现这种效果。具体来说:

$(".nav_button").mouseover(onOver);
$(".nav_button").mouseout(onOut);

和:

function onOver(){
        //var txtwidth = $(this).document.getElementsByClassName("nav_over").clientWidth;
        //var txtwidth = $(this).children(".nav_over").offsetWidth;
        var txtWidth = $(this).children(".project_header").children(".nav_btn").children(".nav_base").width();
        //var txtWidth = document.getElementByClass("nav_base").offsetWidth
        //var txtWidth = $(document).width();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width:txtWidth
        }, speed,"easeOutExpo");
    };
function onOut(){
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width: "0px"
        }, speed,"easeOutExpo");

He's using jQuery to make that effect. Specifically:

$(".nav_button").mouseover(onOver);
$(".nav_button").mouseout(onOut);

and:

function onOver(){
        //var txtwidth = $(this).document.getElementsByClassName("nav_over").clientWidth;
        //var txtwidth = $(this).children(".nav_over").offsetWidth;
        var txtWidth = $(this).children(".project_header").children(".nav_btn").children(".nav_base").width();
        //var txtWidth = document.getElementByClass("nav_base").offsetWidth
        //var txtWidth = $(document).width();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width:txtWidth
        }, speed,"easeOutExpo");
    };
function onOut(){
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").stop();
        $(this).children(".project_header").children(".nav_btn").children(".nav_overlay").animate({
            width: "0px"
        }, speed,"easeOutExpo");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文