<html lang="en">
<head>
<meta charset="UTF-8">
<title>画圆</title>
<script src="http://apps.bdimg.com/libs/raphael/2.1.2/raphael-min.js"></script>
</head>
<body>
<div id="holder"></div>
<script>
var paper = Raphael( "holder", 400, 400 )
var circle = paper.circle(200, 200, 150) // 从200,200 开始画一个半径150的圆
circle.attr("fill", "#f00") //并用红色填充
</script>
</body>
</html>
使用Jquery类库,步骤:
1、准备好html:
<div class="container"><div class="item-list">
<div class="item active"><img src="0.jpg" alt="第1张图"></div>
<div class="item"><img src="1.jpg" alt="第2张图"></div>
<div class="item"><img src="2.jpg" alt="第3张图"></div>
</div>
<div class="item-control">
<a href='javascript:' class="active">●</a>
<a href='javascript:'>●</a>
<a href='javascript:'>●</a>
</div>
</div>
2、为html设置样式
<style>.container{
width: 500px
height: 300px
text-align: center
background: red
position:relative
}
.container>.item-control{
display: inline-block
width: 100%
left: 0
position: absolute
bottom: 10px
background: rgba(0,0,0,0.2)
}
.container>.item-control>a{
font-size: 20px
color: rgba(255,255,255,0.7)
text-decoration: none
}
.container>.item-control>a.active{
color: #fff
}
.container>.item-list,
.container>.item-list>.item{
width: 100%
height: 100%
}
.container>.item-list>.item{
display: none
}
.container>.item-list>.item.active{
display: block
}
</style>
3、编写Js
<script>(function(){
$(document).on('click','.container .item-control a',function(){
var _index = $(this).index()
$(this).addClass('active').siblings().removeClass('active')
$('.container .item-list .item').eq( _index ).addClass('active').siblings().removeClass('active')
})
})()
</script>
最终效果见图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)