直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/banner.css" />
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/banner.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.color.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="banner">
<div class="mork">
<div class="mork-left float-left"><</div>
<div class="mork-right float-right">></div>
</div>
</div>
<div class="icon_btn">
<div class="icon_li">
<div class="perfect-circle float-left" banner-bgk="#000000" id="id0"></div>
<div class="perfect-circle float-left" banner-bgk="#FF0000" id="id1"></div>
<div class="perfect-circle float-left" banner-bgk="#00FF00" id="id2"></div>
<div class="perfect-circle float-left" banner-bgk="#0000FF" id="id3"></div>
<div class="perfect-circle float-left" banner-bgk="#FFFF00" id="id4"></div>
</div>
</div>
</body>
</html>
var currentindex = "id0";
$(document).ready(function() {
//初始化组件宽度
var window_width = $(window).width();
$(".banner").width(window_width);
$(".icon_btn").width(window_width);
var top = $(".banner").offset().top;
var left = $(".banner").offset().left;
var banner_height = $(".banner").height();
var banner_width = $(".banner").width();
$(".mork").css({
"position": "absolute",
"top": top,
"left": left
})
$(".mork-left").css({
"height": banner_height,
"line-height": banner_height + "px"
});
$(".mork-right").css({
"height": banner_height,
"line-height": banner_height + "px",
"position": "relative",
"left": banner_width - 100
});
$('#id0').css({
"background-color": "yellow"
});
$(".mork").hide();
// 实现背景切换
$('.perfect-circle').mouseenter(function() {
$(".perfect-circle").css({
"background-color": "red"
});
var bgk = $(this).attr("banner-bgk");
var bgk = $(this).attr("banner-bgk");
currentindex = $(this).attr("id");
$(this).css({
"background-color": "yellow"
});
$(".banner").css({
"background-color": bgk
});
});
var system = {
win: false,
mac: false,
xll: false,
ipad: false
};
//检测平台
var p = navigator.platform;
alert(p);
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
if(system.win || system.mac || system.xll || system.ipad) {
$('.banner').mouseover(function() {
$(".mork").show();
});
$('.banner').mouseout(function() {
$(".mork").hide();
});
$(".mork-left").click(function() {
var index = currentindex.replace("id", "");
if(parseInt(index) - 1 < 0) {
return;
}
currentindex = "id" + (parseInt(index) - 1);
var bgk = $('#' + currentindex).attr("banner-bgk");
$(".perfect-circle").css({
"background-color": "red"
});
$('#' + currentindex).css({
"background-color": "yellow"
});
$(".banner").css({
"background-color": bgk
});
});
$(".mork-right").click(function() {
var index = currentindex.replace("id", "");
if(parseInt(index) + 1 >= $(".perfect-circle").length) {
return;
}
currentindex = "id" + (parseInt(index) + 1);
var bgk = $('#' + currentindex).attr("banner-bgk");
$(".perfect-circle").css({
"background-color": "red"
});
$('#' + currentindex).css({
"background-color": "yellow"
});
$(".banner").css({
"background-color": bgk
});
});
} else {
$.getScript("js/jquery.mobile-1.3.2.min.js", function() {
$(".banner").on("swipeleft", function() {
var index = currentindex.replace("id", "");
if(parseInt(index) - 1 < 0) {
return;
}
currentindex = "id" + (parseInt(index) - 1);
var bgk = $('#' + currentindex).attr("banner-bgk");
$(".perfect-circle").css({
"background-color": "red"
});
$('#' + currentindex).css({
"background-color": "yellow"
});
$(".banner").css({
"background-color": bgk
});
});
$(".banner").on("swiperight", function() {
var index = currentindex.replace("id", "");
if(parseInt(index) + 1 >= $(".perfect-circle").length) {
return;
}
currentindex = "id" + (parseInt(index) + 1);
var bgk = $('#' + currentindex).attr("banner-bgk");
$(".perfect-circle").css({
"background-color": "red"
});
$('#' + currentindex).css({
"background-color": "yellow"
});
$(".banner").css({
"background-color": bgk
});
});
});
}
setInterval("settime()", 5000);
})
function settime() {
var index = currentindex.replace("id", "");
if(parseInt(index) + 1 >= $(".perfect-circle").length) {
index = -1;
}
currentindex = "id" + (parseInt(index) + 1);
$(".perfect-circle").css({
"background-color": "red"
});
var bgk = $('#' + currentindex).attr("banner-bgk");
$("#" + currentindex).animate({
"backgroundColor": "yellow"
}, 1000)
$(".banner").animate({
"backgroundColor": bgk
}, 1000)
}
@charset "utf-8";
body,h1,h2,h3,h4,h5,h6,dl,dt,dd,ul,ol,li,th,td,p,blockquote,pre,form,fieldset,legend,input,button,textarea,hr {
padding:0;
margin: 0;
}
body{
overflow-x: hidden;
}
ul li{
list-style: none;
}
.float-left{
float: left;
}
.float-right{
float: right;
}
.perfect-circle{
width: 10px;
height: 10px;
background-color: red;
color: white;
text-align: center;
border-radius: 100px;
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
margin: 10px 2px 0 0;
}
.banner{
width: 1000px;
height: 200px;
background-color: #000000;
color: white;
text-align: center;
margin: 0 auto;
}
.icon_btn{
width: 1000px;
margin: 0 auto;
height: 100px;
}
.icon_li{
width: 100px;
margin: 0 auto;
}
.mork-left{
background: blueviolet;
width: 50px;
height: 100px;
text-align: center;
opacity: 0.5;
color: white;
font-size: 50px;
}
.mork-right{
background: blueviolet;
width: 50px;
height: 100px;
text-align: center;
opacity: 0.5;
color: white;
font-size: 50px;
}
.mork-left:hover,.mork-right,.perfect-circle{
cursor:pointer ;
}