我创建了一个颜色函数并给它一个值,它确实有效,但只有当我尝试使用线性渐变时给它一个颜色值时它才不起作用。
我试着把它放在引号里,并确保没有错字或空格
/// 好吧,我解决了它,但知道它在转换之前给了我延迟或闪光注意:它以前没有这样做过。
let image = document.getElementById('main');
let all = document.body;
let container = document.getElementById('container');
let btn = document.getElementById('btn');
let can1 = document.getElementById('can1');
let can2 = document.getElementById('can2');
let can3 = document.getElementById('can3');
let canT = document.getElementById('canT');
let face = document.getElementById('F');
let insta = document.getElementById('I');
let twiter = document.getElementById('T');
function pepsi(aaa) {
image.src = aaa;
}
function color(bbb) {
all.style.background = bbb;
}
function colorc(zzz) {
container.style.background = zzz;
}
canT.onclick = function(){
// functions
pepsi(this.src);
color('linear-gradient(135deg,#000 20%,#4cb705)')
colorc('linear-gradient(135deg,#000 20%,#4cb705)')
// btn fuctions
btn.onmouseenter = function(){
btn.style.backgroundColor = '#4cb705';
btn.style.color = '#000'
} ;
btn.onmouseleave = function(){
btn.style.backgroundColor = '#fff';
btn.style.color = '#000'
}
face.onmouseenter = function(){
face.style.backgroundColor = '#000';
} ;
face.onmouseleave = function(){
face.style.removeProperty('background-color');
}
insta.onmouseenter = function(){
insta.style.backgroundColor = '#000';
} ;
insta.onmouseleave = function(){
insta.style.removeProperty('background-color')
}
twiter.onmouseenter = function(){
twiter.style.backgroundColor = '#000';
} ;
twiter.onmouseleave = function(){
twiter.style.removeProperty('background-color')
}
}
can1.onclick = function(){
// functions
pepsi(this.src);
color('#1a1aff')
colorc(' rgb(9, 59, 158)')
// btn fuctions
btn.onmouseenter = function(){
btn.style.backgroundColor = 'rgb(5, 34, 93)';
btn.style.color = '#fff'
} ;
btn.onmouseleave = function(){
btn.style.backgroundColor = '#fff';
btn.style.color = '#000'
}
face.onmouseenter = function(){
face.style.backgroundColor = 'rgb(5, 34, 93)';
} ;
face.onmouseleave = function(){
face.style.removeProperty('background-color');
}
insta.onmouseenter = function(){
insta.style.backgroundColor = 'rgb(5, 34, 93)';
} ;
insta.onmouseleave = function(){
insta.style.removeProperty('background-color')
}
twiter.onmouseenter = function(){
twiter.style.backgroundColor = 'rgb(5, 34, 93)';
} ;
twiter.onmouseleave = function(){
twiter.style.removeProperty('background-color')
}
}
can2.onclick = function(){
// functions
pepsi(this.src);
color('#404040')
colorc('#666768')
// btn fuctions
btn.onmouseenter = function(){
btn.style.backgroundColor = '#393939';
btn.style.color = '#fff'
} ;
btn.onmouseleave = function(){
btn.style.backgroundColor = '#fff';
btn.style.color = '#000'
}
face.onmouseenter = function(){
face.style.backgroundColor = '#393939';
} ;
face.onmouseleave = function(){
face.style.removeProperty('background-color');
}
insta.onmouseenter = function(){
insta.style.backgroundColor = '#393939';
} ;
insta.onmouseleave = function(){
insta.style.removeProperty('background-color')
}
twiter.onmouseenter = function(){
twiter.style.backgroundColor = '#393939';
} ;
twiter.onmouseleave = function(){
twiter.style.removeProperty('background-color')
}
}
can3.onclick = function(){
// functions
pepsi(this.src);
color('#111')
colorc('#222')
// btn fuctions
btn.onmouseenter = function(){
btn.style.backgroundColor = '#111';
btn.style.color = '#fff'
} ;
btn.onmouseleave = function(){
btn.style.backgroundColor = '#fff';
btn.style.color = '#000'
}
face.onmouseenter = function(){
face.style.backgroundColor = '#111';
} ;
face.onmouseleave = function(){
face.style.removeProperty('background-color');
}
insta.onmouseenter = function(){
insta.style.backgroundColor = '#111';
} ;
insta.onmouseleave = function(){
insta.style.removeProperty('background-color')
}
twiter.onmouseenter = function(){
twiter.style.backgroundColor = '#111';
} ;
twiter.onmouseleave = function(){
twiter.style.removeProperty('background-color')
}
}
*{
margin: 0;
padding: 0;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
html{
scroll-behavior: smooth;
transition: 0.5s;
}
body{
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
background-color: #1a1aff;
transition: 0.5s;
}
#container{
background: rgb(9, 59, 160);
width: 85%;
height: 85%;
position: relative;
box-shadow: 30px 30px 50px #000;
transition: 0.5s;
overflow: hidden;
}
header{
width: 90%;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 0;
}
header a img{
width: 60px;
}
header ul{
display: flex;
}
header ul li {
list-style: none;
margin-right: 20px;
}
header ul li a{
color: #fff;
text-decoration: none;
font-weight: 600;
transition: 0.4s;
}
header ul li a:hover{
color: rgb(0, 0, 0);
}
.content{
width: 100%;
height: 65%;
display: flex;
justify-content: space-around;
align-items: center;
}
.content .image , .content .txt {
width: 40%;
}
.content .image img{
width: 180px;
transform: translateX(130px);
}
.content .txt h2{
color: #fff;
font-size: 50px;
font-weight: 700;
text-transform: uppercase;
}
.content .txt h1{
color: #fff;
font-size: 60px;
font-weight: 800;
text-transform: uppercase;
}
.content .txt p{
color: #fff;
font-size: 20px;
margin: 20px 0;
}
.content .txt a{
color: #000;
text-decoration: none;
font-size: 16px;
word-spacing: 3px;
font-weight: 500;
padding: 10px 18px;
background-color: #fff;
border-radius: 30px;
text-transform: uppercase;
margin-top: 8px;
display: inline-block;
transition: 0.4s;
}
.content .txt a:hover{
color: #fff;
background-color: rgb(5, 34, 93);
transform: scale(1.2);
}
.icons{
position: absolute;
left: 50%;
bottom: 10px;
transform: translateX(-50%);
}
.icons img{
width: 40px;
margin-right: 20px;
transition: 0.3s;
}
.icons img:hover{
cursor: pointer;
padding-bottom: 18px;
}
.links{
position: absolute;
left: 16px;
bottom: 10px;
}
.links a img{
width: 16px;
}
#f{
width: 10px;
}
.links a{
transition: 0.3s;
padding: 9px 9px;
}
.links a:hover{
background-color: rgb(5, 34, 93);
border-radius: 50px;
}
#canT{
width: 45px;
}
@media (max-width:950px) and (min-width:720px){
.links a:hover{
background:none;
}
.links a{
padding: 6px 6px;
}
.links a img{
width: 13px;
transform: translateX(-10px);
}
#f{
width: 8px;
}
header a img{
width: 50px;
}
header ul li {
list-style: none;
margin-right: 17px;
}
header ul li a{
color: #fff;
text-decoration: none;
font-weight: 500;
transition: 0.4s;
}
.content .image img{
width: 140px;
}
.content .txt h2{
color: #fff;
font-size: 30px;
font-weight: 600;
text-transform: uppercase;
}
.content .txt h1{
color: #fff;
font-size: 40px;
font-weight: 700;
text-transform: uppercase;
}
.content .txt p{
color: #fff;
font-size: 18px;
margin: 20px 0;
}
.content .txt a{
font-size: 14px;
word-spacing: 2px;
font-weight: 400;
padding: 8px 15px;
background-color: #fff;
border-radius: 30px;
}
.icons img{
width: 30px;
}
}
@media (max-width:720px){
.links a:hover{
background: none;
}
.links a{
padding: 4px 4px;
}
.links a img{
width: 10px;
transform: translateX(-12px);
}
#f{
width: 7px;
}
header ul li a{
color: #fff;
font-size: 11px;
text-decoration: none;
font-weight: 400;
transition: 0.4s;
}
header ul li {
list-style: none;
margin-right: 15px;
}
header a img{
width: 35px;
}
.content .image img{
width: 90px;
transform: translateX(40px);
}
.content .txt h2{
color: #fff;
font-size: 26px;
font-weight: 500;
text-transform: uppercase;
}
.content .txt h1{
color: #fff;
font-size: 32px;
font-weight: 700;
text-transform: uppercase;
}
.content .txt p{
color: #fff;
font-size: 13px;
margin: 20px 0;
}
.content .txt a{
font-size: 12px;
font-weight: 300;
padding: 5px 10px;
background-color: #fff;
border-radius: 30px;
}
.icons img{
width: 22px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pepsi-Landig page</title>
<link rel="stylesheet" href="pepsi.css">
</head>
<body>
<div id="container">
<header>
<a href="#"><img src="images/logo1.png"></a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">What's New</a></li>
<li><a href="#">About</a></li>
</ul>
</header>
<div class="content">
<div class="txt">
<h2>that's what</h2>
<h1>i like</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Lorem ipsum dolor sit amet. Saepe aut nesciunt eveniet natus, ullam eaque.</p>
<a id="btn" href="#">Veiw all Products</a>
</div>
<div class="image">
<img id="main" src="images/pepsi001.png">
</div>
</div>
<div class="icons">
<img id="canT" src="images/pepsiTwist.png">
<img id="can1" src="images/pepsi001.png">
<img id="can2" src="images/pepsi002.png">
<img id="can3" src="images/pepsi003.png">
</div>
<div class="links">
<a id="F" href="#"><img id="f" src="images/facebook.png"></a>
<a id="I" href="#"><img src="images/twitter.png"></a>
<a id="T" href="#"><img src="images/instagram.png"></a>
</div>
</div>
<script src="pepsi.js"></script>
</body>
</html>