JS+HTML+CSS实现轮播效果

本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下

1.lunbo.html代码:

大轮播

2.CSS/lunbo.css代码:

a {
text-decoration: none;
}

container {

width: 1350px;
height: 618px;
overflow: hidden;
position: relative;
border-top: 1px solid #ac6a0a;
}

list {

width: 6750px;
height: 618px;
position: absolute;
z-index: 1;
}

list img {

float: left;
width: 1350px;
height: 618px;
}

buttons {

position: absolute;
height: 20px;
width: 60px;
z-index: 2;
bottom: 20px;
left: 50%;
}

buttons span {

cursor: pointer;
float: left;
border: 1px solid #ad6a0a;
width: 10px;
height: 10px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
margin-right: 5px;
}

buttons .on {

background: orangered;
}

.arrow {
cursor: pointer;
display: none;
line-height: 100px;
text-align: center;
width: 40px;
height: 40px;
position: absolute;
z-index: 2;
top: 180px;
background-color: RGBA(0,0);
color: #fff;
}

.arrow:hover {
background-color: RGBA(0,0);
}

container:hover .arrow {

display: block;
}

prev {

left: 10px;
color: #ffffff;
}

next {

right: 10px;
color: #ffffff;
}

3.JS/lunbo.js代码:

function animate(offset) {
if (offset == 0) {
return;
}
animated = true;
var time = 300;
var inteval = 10;
var speed = offset / (time / inteval);
console.log("speed:" + speed);
var left = parseInt(list.style.left) + offset;

var go = function () { 
  if ((speed > 0 && parseInt(list.style.left) < left) || (speed < 0 && parseInt(list.style.left) > left)) { 
    list.style.left = parseInt(list.style.left) + speed + 'px'; 
    console.log(list.style.left); 
    setTimeout(go,inteval); 
  } else { 
    list.style.left = left + 'px'; 
    if (left > -200) { 
      list.style.left = -size * len + 'px'; 
    } 
    if (left < ( -size * len)) { 
      list.style.left = '-' + size + 'px'; 
    } 
    animated = false; 
    console.log("left:" + list.style.left); 
  } 
} 
go(); 

}

function showButton() {
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].className == 'on') {
buttons[i].className = '';
break;
}
}
buttons[index - 1].className = 'on';
}

function play() {
timer = setTimeout(function () {
next.onclick();
play();
},interval);
}

function stop() {
clearTimeout(timer);
}

next.onclick = function () {
if (animated) {
return;
}
if (index == len) {
index = 1;
} else {
index += 1;
}
animate(-size);
showButton();
}
prev.onclick = function () {
if (animated) {
return;
}
if (index == 1) {
index = len;
} else {
index -= 1;
}
animate(size);
showButton();
}
for (var i = 0; i < buttons.length; i++) {
buttons[i].onclick = function () {
if (animated) {
return;
}
if (this.className == 'on') {
return;
}
var myIndex = parseInt(this.getAttribute('index'));
var offset = -size * (myIndex - index);

  animate(offset); 
  index = myIndex; 
  showButton(); 
} 

}
container.onmouseover = stop;
container.onmouseout = play;
play();
};

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


kindeditor4.x代码高亮功能默认使用的是prettify插件,prettify是Google提供的一款源代码语法高亮着色器,它提供一种简单的形式来着色HTML页面上的程序代码,实现方式如下: 首先在编辑器里面插入javascript代码: 确定后会在编辑器插入这样的代码: <pre
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代码高亮,因为SyntaxHighlighter的应用非常广泛,所以将kindeditor默认的prettify替换为SyntaxHighlighter代码高亮插件 上一篇“让kindeditor显示高亮代码”中已经
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小
JS怎么获取当前时间戳
JS如何判断对象是否为数组
JS怎么获取图片当前宽高
JS对象如何转为json格式字符串
JS怎么获取图片原始宽高
怎么在click事件中调用多个js函数
js如何往数组中添加新元素
js如何拆分字符串
JS怎么对数组内元素进行求和
JS如何判断屏幕大小
js怎么解析json数据
js如何实时获取浏览器窗口大小
原生JS实现别踩白块小游戏(五)
原生JS实现别踩白块小游戏(一)