Javascript 当显示某个div时,更改div的背景色
我有三个div,一个Twitter帖子,一个Facebook帖子和一个LinkedIn帖子,它们组成了一个旋转木马 这些是另一个名为“社交媒体订阅”的部门 我想知道是否有可能根据旋转木马中的哪个div来改变#社交媒体提要的背景颜色 因此,当twitter部门显示我希望社交媒体订阅源的背景颜色为#00aced时,当facebook部门显示我希望背景颜色为#3b5998时,当linkedin部门显示我希望背景颜色为#007bb5时Javascript 当显示某个div时,更改div的背景色,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有三个div,一个Twitter帖子,一个Facebook帖子和一个LinkedIn帖子,它们组成了一个旋转木马 这些是另一个名为“社交媒体订阅”的部门 我想知道是否有可能根据旋转木马中的哪个div来改变#社交媒体提要的背景颜色 因此,当twitter部门显示我希望社交媒体订阅源的背景颜色为#00aced时,当facebook部门显示我希望背景颜色为#3b5998时,当linkedin部门显示我希望背景颜色为#007bb5时 如果这是可能的话,我真的非常感谢你的帮助。谢谢 这是一个格式非常糟糕
如果这是可能的话,我真的非常感谢你的帮助。谢谢 这是一个格式非常糟糕的代码,但它可以工作。我不能假装知道您的代码是什么样子的,所以我希望这有助于:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, body {
height: 100%;
padding: 0px;
}
#social-media-feeds {
display: inline-block;
height: 100%;
width: 100%;
}
.post {
display: none;
}
#leftButton {
position: absolute;
top: 50%;
left: 0%;
height: 30px;
width: 60px;
text-align: right;
background-color: gray;
cursor: pointer;
}
#rightButton {
position: absolute;
top: 50%;
right: 0%;
height: 30px;
width: 60px;
background-color: gray;
cursor: pointer;
}
</style>
</head>
<body>
<div id="leftButton"><</div>
<div id="rightButton">></div>
<div id="social-media-feeds">
<div id="facebook" class="post">Facebook</div>
<div id="twitter" class="post">Twitter</div>
<div id="linkedIn" class="post">LinkedIn</div>
</div>
<script>
var socialMediaFeedsDiv = document.getElementById('social-media-feeds');
var backgroundColors = ["#3b5998", "#00aced", "#007bb5"];
var posts = document.getElementsByClassName('post');
var index = 0;
posts[index].style.display = 'inline-block';
socialMediaFeedsDiv.style.backgroundColor = backgroundColors[index];
var leftButton = document.getElementById('leftButton');
leftButton.addEventListener('click', function() {
posts[index].style.display = 'none';
index--;
if (index < 0) {
index = posts.length - 1;
}
posts[index].style.display = 'inline-block';
socialMediaFeedsDiv.style.backgroundColor = backgroundColors[index];
});
var rightButton = document.getElementById('rightButton');
rightButton.addEventListener('click', function() {
posts[index].style.display = 'none';
index++;
if (index > (posts.length - 1)) {
index = 0;
}
posts[index].style.display = 'inline-block';
socialMediaFeedsDiv.style.backgroundColor = backgroundColors[index];
});
</script>
</body>
</html>
html,正文{
身高:100%;
填充:0px;
}
#社交媒体订阅源{
显示:内联块;
身高:100%;
宽度:100%;
}
.邮政{
显示:无;
}
#左键{
位置:绝对位置;
最高:50%;
左:0%;
高度:30px;
宽度:60px;
文本对齐:右对齐;
背景颜色:灰色;
光标:指针;
}
#右按钮{
位置:绝对位置;
最高:50%;
右:0%;
高度:30px;
宽度:60px;
背景颜色:灰色;
光标:指针;
}
脸谱网
啁啾
LinkedIn
var socialmediaafeedsdiv=document.getElementById('social-media-feeds');
var BackgroundColor=[“3b5998”、“00aced”、“007bb5”];
var posts=document.getElementsByClassName('post');
var指数=0;
posts[index].style.display='inline block';
socialMediaFeedsDiv.style.backgroundColor=背景色[索引];
var leftButton=document.getElementById('leftButton');
leftButton.addEventListener('单击',函数()){
posts[index].style.display='none';
索引--;
如果(指数<0){
指数=posts.length-1;
}
posts[index].style.display='inline block';
socialMediaFeedsDiv.style.backgroundColor=背景色[索引];
});
var rightButton=document.getElementById('rightButton');
rightButton.addEventListener('单击',函数()){
posts[index].style.display='none';
索引++;
如果(索引>(posts.length-1)){
指数=0;
}
posts[index].style.display='inline block';
socialMediaFeedsDiv.style.backgroundColor=背景色[索引];
});
请出示您的代码。例如:我们在这里是程序员,我们可以阅读代码。这绝对是可能的,可能是通过使用您的旋转木马的回调,但您仍然需要向我们展示一些代码。请提供您的旋转木马代码片段。