利用JS做網(wǎng)頁(yè)特效_大圖輪播(實(shí)例講解)
廢話不多說(shuō),直接上代碼:
<style>
* {
margin: 0px;
padding: 0px;
}
.stage {
width: 500px;
height: 300px;
border: 5px solid black;
margin: 200px;
position: relative;
overflow: hidden;
}
.to-left,
.to-right {
position: absolute;
top: 0px;
width: 50px;
height: 300px;
background-color: black;
color: white;
font-size: 30px;
text-align: center;
line-height: 300px;
opacity: 0.3;
}
.to-left {
left: 0px;
}
.to-right {
right: 0px;
}
.to-left:hover,
.to-right:hover {
cursor: pointer;
opacity: 0.5;
}
.banner {
width: 3000px;
height: 300px;
}
.items {
float: left;
width: 500px;
height: 300px;
background-color: blanchedalmond;
font-size: 100px;
text-align: center;
line-height: 300px;
}
</style>
</head>
<!--大圖輪播特效-->
<body>
<div class="stage">
<div class="to-left">
<</div>
<div class="to-right">></div>
<div class="banner">
<div class="items">1</div>
<div class="items" style="">2</div>
<div class="items" style="">3</div>
<div class="items" style="">4</div>
<div class="items" style="">5</div>
<div class="items">1</div>
</div>
</div>
</body>
</html>
<script>
var to_right = document.getElementsByClassName('to-right')[0];
var to_left = document.getElementsByClassName('to-left')[0];
var banner = document.getElementsByClassName('banner')[0];
var arr = [];
var count = 1;
to_right.onclick = function() {
toRight();
}
function toRight(){
arr.push(window.setInterval("moveLeft()", 30));
}
to_left.onclick = function() {
toLeft();
}
function toLeft(){
arr.push(window.setInterval("moveRight()", 30));
}
function moveLeft() {
if(count < 5) {
if(banner.offsetLeft > count * (-500)) {
banner.style.marginLeft = banner.offsetLeft - 20 + "px";
} else {
for(var x in arr) {
window.clearInterval(arr[x]);
}
count++;
}
// 連接點(diǎn)
}else{
if(banner.offsetLeft > count * (-500)) {
banner.style.marginLeft = banner.offsetLeft - 20 + "px";
} else {
for(var x in arr) {
window.clearInterval(arr[x]);
}
count = 1;
banner.style.marginLeft = 0 + 'px';
}
}
}
function moveRight() {
if(count-1 >0) {
if(banner.offsetLeft < (count-2) * (-500)) {
banner.style.marginLeft = banner.offsetLeft + 20 + "px";
} else {
for(var x in arr) {
window.clearInterval(arr[x]);
}
count--;
}
}
}
window.setInterval("toRight()",1750);
</script>
以上這篇利用JS做網(wǎng)頁(yè)特效_大圖輪播(實(shí)例講解)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript Perfection kill 測(cè)試及答案
近日,在Perfection kill上看到有關(guān)javascript quiz。并做了一下,最終錯(cuò)了2個(gè)(#2,#9),但是,這2道題,在Ie和ff下的答案是不一樣的?!2010-03-03
js css實(shí)現(xiàn)垂直方向自適應(yīng)的三角提示菜單
這篇文章主要為大家詳細(xì)介紹了js css實(shí)現(xiàn)垂直方向自適應(yīng)的三角提示菜單的相關(guān)資料,需要的朋友可以參考下2016-06-06
ES6基礎(chǔ)之?dāng)?shù)組和對(duì)象的拓展實(shí)例詳解
這篇文章主要介紹了ES6基礎(chǔ)之?dāng)?shù)組和對(duì)象的拓展,結(jié)合實(shí)例形式詳細(xì)分析了ES6數(shù)組和對(duì)象拓展運(yùn)算符、拓展方法的使用及相關(guān)操作技巧,需要的朋友可以參考下2019-08-08
JS實(shí)現(xiàn)超簡(jiǎn)單的仿QQ折疊菜單效果
這篇文章主要介紹了JS實(shí)現(xiàn)超簡(jiǎn)單的仿QQ折疊菜單效果,可實(shí)現(xiàn)鼠標(biāo)滑過(guò)列表展開(kāi)的QQ折疊菜單效果,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-09-09
document.getElementById為空或不是對(duì)象的解決方法
document.getElementById為空或不是對(duì)象的解決方法,一般情況下注意先內(nèi)容后js.2010-01-01
JavaScript獲取網(wǎng)頁(yè)支持表單字符集的方法
這篇文章主要介紹了JavaScript獲取網(wǎng)頁(yè)支持表單字符集的方法,涉及javascript中acceptCharset方法的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
js+css實(shí)現(xiàn)的圓角邊框TAB選項(xiàng)卡滑動(dòng)門(mén)代碼分享(2款)
這篇文章主要為大家詳細(xì)介紹了兩種js+css實(shí)現(xiàn)的圓角邊框TAB選項(xiàng)卡滑動(dòng)門(mén)效果,很實(shí)用的代碼,推薦給大家,有需要的小伙伴可以參考下2015-08-08

