JQ minimal code to achieve focus map with numbers and arrows

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQ minimal code to achieve focus map with numbers and arrows</title>
<link rel="stylesheet" href="base.css" />
<script type="text/javascript" src="jquery-1.10.1.min.js" ></script>
<style type="text/css">
.t-banner {
	position: relative;
	width: 500px;
	height: 350px;
	margin: 40px auto;
}
.m-banner {
	float: left;
	position: absolute;
	overflow: hidden;
	width: 500px;
	height: 350px;
}
.ui-banner {
	position: absolute;
	overflow: hidden;
	width: 2000px;
}
.ui-banner img {
	float: left;
	width: 500px;
	height: 350px;
}
.ui-number {
	position: absolute;
	bottom: 15px;
	left: 210px;
	width: 200px;
}
.ui-number li {
	float: left;
	width: 20px;
	height: 20px;
	line-height: 20px;
	text-align: center;
	margin-right: 5px;
	border: 1px solid #ddd;
	border-radius: 5px;
	font-size: 14px;
	background: #fff;
	cursor: pointer;
}
.ui-number li.lb-number-current {
	background: #f60;
	color: #fff;
}
.ui-arrows {
	color: #666;
	font-size: 40px;
	font-weight: bold;
}
.ui-arrows a {
	background: rgba(0,0,0,0.2);
	display: inline-block;
	width: 30px;
	height: 70px;
	text-align: center;
	color: #fff;
	line-height: 70px;
}
.ui-arrows a:hover {
	background: rgba(0,0,0,0.5);
	color: #fff;
}
.lb-arrows-pre {
	position: absolute;
	top: 120px;
	left: 0;
}
.lb-arrows-next {
	position: absolute;
	top: 120px;
	right: 0;
}
</style>
</head>
<body>
<div class="t-banner">
    <div class="m-banner">
        <ul class="ui-banner">
            <li><img src="img/aaa.png"/></li>
            <li><img src="img/bbb.png"/></li>
            <li><img src="img/ccc.png"/></li>
            <li><img src="img/ddd.png"/></li>
        </ul>
        <p class="ui-arrows">
            <a class="lb-arrows-pre"><</a>
            <a class="lb-arrows-next">></a>
        </p>
        <ol class="ui-number">
            <li class="lb-number-current">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ol>
    </div>
</div>
<script>
$(function(){
	//focus map
	focusMap();
});
function focusMap(){
	var now = 0;
    var banner = $(".ui-banner");
    var num = $(".ui-number li");
    var wid = $(".m-banner").eq(0).width();
    //The numbers correspond to the pictures
    num.click(function(){
        var index = $(this).index();
        $(this).addClass("lb-number-current").siblings().removeClass();
        banner.animate({'left': -wid * index}, 500);
    })
    // left and right arrows rotate
    $(".lb-arrows-pre").click(function(){
    	now>=1 ? now-- : now=num.size()-1;
        years();
    });
    $(".lb-arrows-next").click(function(){
    	now==num.size()-1 ? now = 0 : now++;
        years();
    });
    //animation effect
    function ani () {
        num.eq(now).addClass("lb-number-current").siblings().removeClass();
        banner.animate({'left': -wid * now}, 500);
    }
    // timer
    var isInterval=setInterval(getIndex,2000);
    function getIndex(){
    	now == num.size()-1 ? now = 0 : now++;
        years();
    }
    // Stop the automatic animation when the mouse stays on the screen, and resume when leaving
    $(".m-banner").mouseover(function(){
        clearTimeout(isInterval);
    });
    $(".m-banner").mouseout(function(){
        isInterval=setInterval(getIndex,2000);
    });
}
</script>
</body>
</html>

   

Effect picture:

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326936343&siteId=291194637