gpt4 book ai didi

javascript - 如何使用条件为 'IF' 的按钮更改具有功能的 DIV 的背景颜色

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:59 25 4
gpt4 key购买 nike

我的问题可能有点含糊,但这就是我现在所拥有的。 Here's the fiddle I did

每次单击橙色背景 按钮 并且仅当 更多 div 仍在屏幕底部(单击时更多按钮会向上滑动)

this is how

还有我的一些代码片段:

<script>

$(document).ready(function(){
$('.chatbox').hide();
$('#btn-chat').click(function() {
$("#blk-collaboration .chatbox").slideToggle("slow",function(){
$("#blk-collaboration #toggle").css("background","transparent");
});
$(this)//this is a button DOM element. wrapping in jQuery object.
.toggleClass('wide'); // removing wide class so button became smaller.
});
});

function changeColor(color) {
document.getElementById("circle").style.backgroundColor = color;
}

document.getElementById("online").onclick = function() { changeColor("#92bf1e"); }
document.getElementById("offline").onclick = function() { changeColor("#747474"); }
document.getElementById("upcoming").onclick = function() { changeOrange("#f4b066"); }



</script>

这是按钮...

<input id="online" type="button" value="Online" />
<input id="offline" type="button" value="Offline" />
<input id="upcoming" type="button" value="Orange Background" />

一直在尝试解决这个问题,但是 more button 的颜色仍然会改变,即使它已经向上滑动了......

最佳答案

应该这样做,在 changeColor 函数下面添加:

function changeOrange(color) {
if ($('#btn-chat').hasClass('wide'))
document.getElementById("btn-chat").style.backgroundColor = color;
}

如果背景已经是橙色,并且更多按钮向上移动,背景是否应该变回蓝色?

关于javascript - 如何使用条件为 'IF' 的按钮更改具有功能的 DIV 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26030228/

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