百度換膚
<style>
* {
margin: 0;
padding: 0;
}
list {
list-style: none;
}
body {
background: url(picture/1.jpg) no-repeat center top;
}
.baidu {
overflow: hidden;
margin: 100px auto;
width: 410px;
background-color: #fff;
padding-top: 4px;
}
</style>
<body>
<ul class="baidu">
<li><img src="picture/1.jpg" alt=""></li>
<li><img src="picture/2.jpg" alt=""></li>
<li><img src="picture/3.png" alt=""></li>
<li><img src="picture/4.jpg" alt=""></li>
</ul>
<script>
var imgs = document.querySelector('.baidu').querySelectorAll('img');
for (var i = 0; i < imgs.length; i++) {
imgs[i].onclick = function() {
document.body.style.backgroundImage = 'url(' + this.src + ')';
}
}
</script>
</body>
顯示隱藏文本框內容
<body>
<input type="text" value="手機">
<script>
var text = document.querySelector('input');
// 獲得焦點
text.onfocus = function() {
if (this.value === '手機') {
this.value = '';
}
this.style.color = '#333';
}
// 失去焦點
text.onblur = function() {
if (this.value === '') {
this.value = '手機';
}
this.style.color = '#999'
}
</script>
</body>
排他思想實作按鈕變色
<body>
<button>按鈕1</button>
<button>按鈕2</button>
<button>按鈕3</button>
<button>按鈕4</button>
<button>按鈕5</button>
</body>
<script>
var btns = document.getElementsByTagName('button');
for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function() {
for (var i = 0; i < btns.length; i++) {
btns[i].style.backgroundColor = '';
}
this.style.backgroundColor = 'pink';
}
}
</script>
三個非常基礎的案例,適用于初學者寫網頁的運用,通過自己的創造和靈感能夠寫出許多有意思的網頁效果,js可以給網頁更多的動態效果,使網站更加的靈活,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/277681.html
標籤:其他
上一篇:【60】移動WEB開發(7)——布局常見方式①流式布局(附實踐案例)
下一篇:Vue---組件詳解
