gpt4 book ai didi

html - 几乎相同页面之间的 CSS 过渡

转载 作者:太空宇宙 更新时间:2023-11-04 10:37:13 25 4
gpt4 key购买 nike

我有两个页面,index.html 和 about.html,都使用相同的 CSS 样式。

在我的网站上,有两个链接是关于和主页。这两个页面之间的唯一区别是显示的段落文本(导航和页脚相同)。

当从主页点击关于链接时,如何为页面/文本创建过渡,反之亦然?

默认的缓动过渡是我正在寻找的,假设我给了段落一个 id = "target"

在我的 css 文件中,我会做类似的事情吗

#target {
transition: 1s;
}

我不知道我需要指定什么 css 属性。

最佳答案

它需要一些 JavaScript 或 JQuery。

HTML

<a id="homeLink">Home</a>
<a id="aboutLink">About</a>

<p id="targetHome">This is the home Paragraph...</p>
<p id="targetAbout" class="hidden">This is the about Paragraph...</p>

JS

$(document).on("click", "#aboutLink", function(e){
e.preventDefault(); //Prevent the <a> element from redirecting
$("#targetHome:visible").hide("fade", 300, function(){
$("#targetAbout:hidden").show("fade", 300); //Show About Paragraph if hidden
});
});

$(document).on("click", "#homeLink", function(e){
e.preventDefault(); //Prevent the <a> element from redirecting
$("#targetAbout:visible").hide("fade", 300, function(){
$("#targetHome:hidden").show("fade", 300); //Show Home Paragraph if hidden
});
});

关于html - 几乎相同页面之间的 CSS 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36063948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com