50 天学习 50 个项目 - HTMLCSS and JavaScript
day43-Feedback Ui Design(反馈ui设计)
效果
index.html
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" /> < meta name = " viewport" content = " width=device-width, initial-scale=1.0" /> < title> Let Us Know Your Feedback</ title> < link rel = " stylesheet" href = " https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity = " sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin = " anonymous" /> < link rel = " stylesheet" href = " style.css" />
</ head> < body> < div id = " panel" class = " panel-container" > < strong> 你对我们的服务表现满意吗?</ strong> < div class = " ratings-container" > < div class = " rating" > 不好</ div> < div class = " rating" > 一般</ div> < div class = " rating active" > 满意</ div> </ div> < button class = " button" id = " send" > 发送</ button> </ div> < script src = " script.js" > </ script>
</ body> </ html>
style.css
@import url ( 'https://fonts.googleapis.com/css?family=Montserrat&display=swap' ) ; * { box-sizing : border-box;
} body { background : url ( 'https://source.unsplash.com/random' ) no-repeat center/cover; font-family : 'Montserrat' , sans-serif; display : flex; align-items : center; justify-content : center; height : 100vh; overflow : hidden; margin : 0;
}
.panel-container { background-color : #fff; box-shadow : 0 0 10px rgba ( 0, 0, 0, 0.3) ; border-radius : 4px; font-size : 90%; display : flex; flex-direction : column; justify-content : center; align-items : center; text-align : center; padding : 30px; max-width : 400px; transition : transform 0.5s linear;
}
.changeCard { transform : rotateY ( 360deg) ;
}
.panel-container strong { line-height : 20px;
}
.ratings-container { display : flex; margin : 20px 0;
}
.rating { flex : 1; cursor : pointer; padding : 20px; margin : 10px 5px; background : linear-gradient ( 145deg, #cacaca, #f0f0f0) ;
}
.rating:hover,
.rating.active { border-radius : 4px; box-shadow : 0 0 10px rgba ( 0, 0, 0, 0.98) ;
}
.button { cursor : pointer; position : relative; padding : 10px 24px; font-size : 18px; color : rgb ( 98, 177, 193) ; border : 2px solid rgb ( 98, 136, 193) ; border-radius : 34px; background-color : transparent; font-weight : 600; transition : all 0.3s cubic-bezier ( 0.23, 1, 0.320, 1) ; overflow : hidden;
}
.button::before { content : '' ; position : absolute; inset : 0; margin : auto; width : 50px; height : 50px; border-radius : inherit; scale : 0; z-index : -1; background-color : rgb ( 114, 135, 238) ; transition : all 0.6s cubic-bezier ( 0.23, 1, 0.320, 1) ;
} .button:hover::before { scale : 3;
} .button:hover { color : #212121; scale : 1.1; box-shadow : 0 0px 20px rgba ( 193, 163, 98, 0.4) ;
} .button:active { scale : 1;
}
.fa-heart { color : red; font-size : 30px; margin-bottom : 10px;
}
script.js
const ratings = document. querySelectorAll ( '.rating' )
const ratingsContainer = document. querySelector ( '.ratings-container' )
const sendBtn = document. querySelector ( '#send' )
const panel = document. querySelector ( '#panel' )
let selectedRating = '满意'
ratingsContainer. addEventListener ( 'click' , ( e ) => { document. querySelector ( '.rating.active' ) . classList. remove ( 'active' ) e. target. classList. add ( 'active' ) selectedRating = e. target. innerText
} )
sendBtn. addEventListener ( 'click' , ( ) => { panel. innerHTML = ` <i class="fas fa-heart"></i><strong>感谢!</strong><br><strong>您的反馈为: ${ selectedRating} </strong><p>我们将利用您的反馈来改进我们的服务</p> ` panel. classList. add ( 'changeCard' )
} )