123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- /* css reset */
- * {
- margin: 0;
- padding: 0;
- }
- li {
- list-style: none;
- }
- /* 工具类 */
- .main-width {
- width: 1226px;
- margin: 0 auto;
- }
- body {
- background-color: rgb(249, 250, 251);
- }
- /* header start */
- header {
- height: 100px;
- background-color: #4F46E5;
- color: #fff;
- }
- header .main-width {
- display: flex;
- flex-direction: column;
- justify-content: center;
- height: 100%;
- }
- /* header end */
- /* content start */
- .content {
- padding-top: 80px;
- display: flex;
- justify-content: space-between;
- }
- .content aside h2 {
- margin-bottom: 30px;
- }
- .content aside {
- width: 480px;
- height: 830px;
- background-color: #fff;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
- border-radius: 10px;
- padding: 30px 20px;
- box-sizing: border-box;
- }
- .content aside p {
- margin: 10px 0;
- }
- .content aside input[type="range"] {
- width: 100%;
- background-color: rgb(229, 231, 235);
- /* -webkit-appearance:none; */
- }
- .content .color-content {
- display: flex;
- }
- .content .color-content input[type="color"] {
- width: 40px;
- height: 40px;
- margin-right: 10px;
- }
- .content .color-content input[type="text"] {
- width: 100px;
- height: 36px;
- flex-grow: 1;
- border: 1px solid rgb(209, 213, 219);
- border-radius: 5px;
- }
- .content .inp9 button {
- width: 100%;
- height: 50px;
- background-color: rgb(243, 244, 246);
- border: none;
- font-size: 20px;
- font-weight: bold;
- margin-top: 20px;
- }
- .content select {
- width: 100%;
- height: 36px;
- border: 1px solid rgb(209, 213, 219);
- border-radius: 5px;
- }
- .content article {
- width: 710px;
- height: 830px;
- background-color: #fff;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
- border-radius: 10px;
- padding: 30px 20px;
- box-sizing: border-box;
- }
- .content article .bg {
- background-color: #aaa;
- width: 100%;
- height: 650px;
- margin-top: 30px;
- border-radius: 10px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .content article .box {
- width: 200px;
- height: 200px;
- background-color: gray;
- border: 1px solid blue;
- display: flex;
- justify-content: center;
- align-items: center;
- transition: all 0.5s linear;
- border-radius: 10px;
- }
- /* content end */
- </style>
- </head>
- <body>
- <div class="container">
- <header>
- <div class="main-width">
- <h1>交互式元素编辑器</h1>
- <p>通过表单控件实时修改元素样式和内容</p>
- </div>
- </header>
- <div class="content main-width">
- <aside>
- <form>
- <h2>控制面板</h2>
- <div class="inp1">
- <p>元素大小: 200px</p>
- <input type="range" min="100" max="400">
- </div>
- <div class="inp2">
- <p>圆角大小: 10px</p>
- <input type="range" min="0" max="50">
- </div>
- <div class="inp3">
- <p>背景颜色</p>
- <div class="color-content">
- <input type="color">
- <input type="text">
- </div>
- </div>
- <div class="inp4">
- <p>元素文本</p>
- <div class="color-content">
- <input type="text">
- </div>
- </div>
- <div class="inp5">
- <p>文本颜色</p>
- <div class="color-content">
- <input type="color">
- <input type="text">
- </div>
- </div>
- <div class="inp6">
- <p>边框样式</p>
- <select>
- <option value="solid">实线</option>
- <option value="dashed">虚线</option>
- <option value="dotted">点线</option>
- </select>
- </div>
- <div class="inp7">
- <p>边框宽度: 2px</p>
- <input type="range" min="1" max="10">
- </div>
- <div class="inp8">
- <p>阴影效果</p>
- <input type="checkbox" id="is-shadow">
- <label for="is-shadow">开启阴影</label>
- </div>
- <div class="inp9">
- <button type="reset">重置样式</button>
- </div>
- </form>
- </aside>
- <article>
- <h2>预览区域</h2>
- <div class="bg">
- <div class="box">
- hello world
- </div>
- </div>
- </article>
- </div>
- <footer>
- </footer>
- </div>
- <script>
- // 获取元素
- var oBox = document.querySelector(".box");
- // 绑定事件
- // 元素大小
- var inp1 = document.querySelector(".inp1");
- var inp1Text = inp1.querySelector("p");
- inp1 = inp1.querySelector("input");
- inp1.oninput = function () {
- console.log(this.value);
- inp1Text.innerText = "元素大小:" + this.value + "px";
- oBox.style.width = this.value + "px";
- oBox.style.height = this.value + "px";
- }
- // 圆角大小
- var inp2 = document.querySelector(".inp2 input");
- var inp2Text = document.querySelector(".inp2 p");
- console.log(inp2)
- inp2.oninput = function () {
- oBox.style.borderRadius = this.value + "px";
- inp2Text.innerText = "圆角大小:" + this.value + "px";
- }
- // 修改背景色
- var inp3 = document.querySelector(".inp3 input[type='color']");
- var inp3Text = document.querySelector(".inp3 input[type='text']");
- inp3.oninput = function () {
- oBox.style.backgroundColor = this.value;
- inp3Text.value = this.value;
- }
- // 改变文本内容
- var inp4 = document.querySelector(".inp4 input");
- inp4.oninput = function () {
- oBox.innerText = this.value;
- }
- // 改变文本颜色
- var inp5 = document.querySelector(".inp5 input[type='color']");
- var inp5Text = document.querySelector(".inp5 input[type='text']");
- inp5.oninput = function () {
- oBox.style.color = this.value;
- inp5Text.value = this.value;
- }
- // 改变边框样式
- var inp6 = document.querySelector(".inp6 select");
- inp6.onchange = function () {
- console.log(this.value);
- oBox.style.borderStyle = this.value;
- }
- // 改变边框宽度
- var inp7 = document.querySelector(".inp7 input");
- var inp7Text = document.querySelector(".inp7 p");
- inp7.oninput = function(){
- oBox.style.borderWidth = this.value + "px";
- inp7Text.innerText = "边框宽度:" + this.value + "px";
- }
- // 改变阴影效果
- var inp8 = document.querySelector(".inp8 input");
- inp8.onchange = function(){
- console.log(this.checked)
- if(this.checked){
- oBox.style.boxShadow = "0 0 10px rgba(0,0,0,0.5)";
- }else{
- oBox.style.boxShadow = "none";
- }
- }
- // 重置样式
- var inp9 = document.querySelector(".inp9 button");
- inp9.onclick = function(){
- oBox.style = "";
- }
- </script>
- </body>
- </html>
|