写了个Demo。
今天太晚了,明天再来写详细内容。
续写:
HTML:
- <div class="picbox">
- <a class="last transition roll nopic" href="#"><</a>
- <ul class="rollpic transition">
- <li><img src="images/xx.jpg"></li>
- <li><img src="images/1.png"></li>
- <li><img src="images/xx.jpg"></li>
- <li><img src="images/1.png"></li>
- <li><img src="images/xx.jpg"></li>
- <li><img src="images/1.png"></li>
- </ul>
- <a class="next transition roll" href="#">></a>
- </div>
JS:
- var picwidth = parseInt($('.picbox').css('width'));
- var piccount = $('.rollpic li').length;
- var nowindex = 1;
- // console.log(piccount);
- $('.next').click(function(event) {
- if(checknowpic(event.target)){
- nowindex++;
- var nowpicleft = (nowindex-1)*picwidth*-1;
- $('.rollpic').css('left',nowpicleft);
- updateroll(nowindex);
- }
- return false;
- });
- $('.last').click(function(event) {
- if(checknowpic(event.target)){
- nowindex--;
- var nowpicleft = (nowindex-1)*picwidth*-1;
- $('.rollpic').css('left',nowpicleft);
- updateroll(nowindex);
- }
- return false;
- });
- function checknowpic(obj){
- var nowpicleft = parseInt($('.rollpic').css('left'));
- /* Act on the event */
- if($(obj).attr('class').indexOf('nopic')>-1){
- return false;
- }else{
- return true;
- }
- }
- function updateroll(now){
- var nowpicleft = parseInt($('.rollpic').css('left'));
- console.log(now);
- if(now == piccount){
- $('.next').addClass('nopic');
- }else{
- $('.next').removeClass('nopic');
- }
- if(now == 1){
- $('.last').addClass('nopic');
- }else{
- $('.last').removeClass('nopic');
- }
- }
CSS:
- .picbox {
- position: relative;
- width: 400px;
- height: 300px;
- border: 1px solid #ff00ff;
- margin: 0 auto;
- overflow: hidden;
- }
- .picbox .last,
- .picbox .next {
- line-height: 40px;
- position: absolute;
- font-size: 20px;
- color: #fff;
- background: rgba(0, 0, 0, 0.5);
- top: 130px;
- text-decoration: none;
- padding: 0 10px;
- z-index: 999;
- }
- .picbox .last.nopic,
- .picbox .next.nopic {
- background: rgba(0, 0, 0, 0.1);
- }
- .picbox .last.nopic:hover,
- .picbox .next.nopic:hover {
- background: rgba(0, 0, 0, 0.1);
- }
- .picbox .last:hover,
- .picbox .next:hover {
- background: rgba(0, 0, 0, 0.8);
- }
- .picbox .last {
- left: -32px;
- }
- .picbox .next {
- right: -32px;
- }
- .picbox .rollpic {
- position: absolute;
- left: 0 ;
- width: 4000px;
- height: 300px;
- list-style-type: none;
- }
- .picbox .rollpic li {
- float: left;
- width: 400px;
- height: 300px;
- cursor: pointer;
- overflow: hidden;
- }
- .picbox .rollpic li img {
- width: 100%;
- height: 100%;
- }
- .picbox .rollpic.transition {
- transition-duration: .5s;
- transition-property: left;
- transition-timing-function: ease;
- }
- .picbox:hover .last {
- left: 0px;
- }
- .picbox:hover .next {
- right: 0px;
- }
还一个base.css就不写了,源码里有的。
Comments NOTHING