gpt4 book ai didi

jquery - 使用 jQuery 更改 Div 颜色的问题

转载 作者:太空宇宙 更新时间:2023-11-04 03:14:04 24 4
gpt4 key购买 nike

好的,这就是我得到的:

<!DOCTYPE html>
<html>
<head>
<title>The Down-Champlain Regatta</title>
<link rel="stylesheet" href="homepage.css"/>
<link href='http://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
<script src="jquery-1.11.2.js"></script>
<script src="jquery-ui.js"></script>
</head>
<body>
<div id="topcontainer">
<img src="Images/Kim.jpg" id="tom">
<img src="Images/Kim.jpg" id="zach">

<div id="head">
<p id="a">Hello South Burlington. We're the</p>
<h5>Down Champlain Regatta.</h5>
<p id="s">And we've got a bold new plan for sailing education on Lake Champlain.</p>
</div>

<div id="down">
<p>check it out</p>
</div>
</div>

<div id="container">
<h5>Here's What We're Doing</h5>
<p class="beginning">The most important thing in sailing is experience. Read all the books you want - you'll still need time on the water.</p>
<p>The Down Champlain Regatta is a non-profit organization designed to give students, if nothing else, tons of time on the water. Its three weeks of all-weather keelboat sailing on Lake Champlain, something not offered in many other places, will teach students more than anything else can.</p>
<p>This course is not for new sailors. It's for kids who know how to sail, but want to take it to the next level. It's for kids who want to move up into the world of keelboat racing.</p>
<p>And at the end of the course, they do just that. The course finishes with an all-day, student-led race down Lake Champlain. This is a unique opportunity for the students to apply their newly learned skills, build confidence, and get exposure in the racing community. </p>

</div>

<script type="text/javascript">
$(document).ready(function(){
$("#down").mouseover(function(){
$("#down").animate({backgroundColor: "#1363bf"}, 2000)
});

$("#down").mouseout(function(){
$("#down").animate({backgroundColor: "#e03535"}, 250)
});

$("#down").click(function(){
$("html, body").animate({
scrollTop: $("#container").position().bottom+"px"
}, 800)
});
});
</script>
</body>
</html>

基本上,有一个 div,我希望当您将鼠标悬停在它上面时它会改变颜色。

看,问题是 .mouseover 正在检测 div 和其中的段落(“检查它”)。因此,当您将鼠标悬停在 div 和段落上时,它会经历两次颜色变化。有没有办法解决?也许使用 .mouseover 以外的东西?

这是 dwreck08 的更新代码:

    $("#down").mouseover(function(){
$("#down").not("p").animate({backgroundColor: "#1363bf"}, 2000)
});

$("#down").mouseout(function(){
$("#down").not("p").animate({backgroundColor: "#e03535"}, 250)
});

最佳答案

正如@Albin 的评论所述,我还建议使用 css3 转换来实现这一点。如果愿意,您仍然可以使用 jquery 来切换它:JS Fiddle

 $("#down").mouseover(function () {
$("#down").css('background', 'blue');
});

$("#down").mouseout(function () {
$("#down").css('background', 'red');
});


#down {
transition: 1s;
}
#down:hover {
transition: 2s;
}

关于jquery - 使用 jQuery 更改 Div 颜色的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29013677/

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