jQuery jslides 1.1.0 - 一款横向宽屏banner图片切换特效
  • 分享到微信朋友圈
    X

文章内容

介绍一款横向宽屏基于jquery的banner图片切换特效,代码简单直接引用就行.

1:引入必要的文件

<link href="css/index.css" rel="stylesheet" type="text/css" />
<script src="jquery/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.jslides.js"></script>

2:HTML代码

<!--banner-->
<div id="full-screen-slider">
    <ul id="slides">
        <li style="background: url('images/banner.jpg') no-repeat center"></li>
        <li style="background: url('images/banner1.jpg') no-repeat center"></li>
        <li style="background: url('images/banner.jpg') no-repeat center"></li>
    </ul>
</div>

index.css代码

* {
    margin: 0;
    padding: 0; 
}
ol, ul {
    list-style: none;
}

/*banner*/
#full-screen-slider{width:100%; height:540px; position:relative; z-index:0; overflow:hidden; }
#slides{display:block; width:100%; height:540px; list-style:none; padding:0; position:relative}
#slides li{display:block; width:100%; height:540px; list-style:none; padding:0; margin:0; position:absolute; left:0;}
#slides li a{display:block; width:100%; height:540px; text-indent:-9999px}
#pagination{display:block; list-style:none; position:absolute; left:50%; bottom:30px; height:10px; z-index:999; padding:5px 15px 5px 0; margin:0}
#pagination li{display:block; list-style:none; width:18px; height:18px; float:left; margin-left:15px; background:#d89b05; border-radius:18px; }
#pagination li a{display:block; width:100%; height:18px; padding:0; margin:0; text-indent:-999em;}
#pagination li.current{ background:#FF0000; }
/*banner*/

jquery.jslides.js代码

/**
 * jQuery jslides 1.1.0
 *
 * http://www.cactussoft.cn
 *
 * Copyright (c) 2009 - 2013 Jerry
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
$(function(){
	var numpic = $('#slides li').size()-1;
	var nownow = 0;
	var inout = 0;
	var TT = 0;
	var SPEED = 5000;


	$('#slides li').eq(0).siblings('li').css({'display':'none'});


	var ulstart = '
<ul id="pagination">
    ', ulcontent = '', ulend = '</ul>';
	ADDLI();
	var pagination = $('#pagination li');
	var paginationwidth = $('#pagination').width();
	$('#pagination').css('margin-left',('-58px'))
	
	pagination.eq(0).addClass('current')
		
	function ADDLI(){
		//var lilicount = numpic + 1;
		for(var i = 0; i <= numpic; i++){
			ulcontent += '
<li>' + '<a href="#">' + (i+1) + '</a>' + '</li>';
		}
		
		$('#slides').after(ulstart + ulcontent + ulend);	
	}

	pagination.on('click',DOTCHANGE)
	
	function DOTCHANGE(){
		
		var changenow = $(this).index();
		
		$('#slides li').eq(nownow).css('z-index','900');
		$('#slides li').eq(changenow).css({'z-index':'800'}).show();
		pagination.eq(changenow).addClass('current').siblings('li').removeClass('current');
		$('#slides li').eq(nownow).fadeOut(400,function(){$('#slides li').eq(changenow).fadeIn(500);});
		nownow = changenow;
	}
	
	pagination.mouseenter(function(){
		inout = 1;
	})
	
	pagination.mouseleave(function(){
		inout = 0;
	})
	
	function GOGO(){
		
		var NN = nownow+1;
		
		if( inout == 1 ){
			} else {
			if(nownow < numpic){
			$('#slides li').eq(nownow).css('z-index','900');
			$('#slides li').eq(NN).css({'z-index':'800'}).show();
			pagination.eq(NN).addClass('current').siblings('li').removeClass('current');
			$('#slides li').eq(nownow).fadeOut(400,function(){$('#slides li').eq(NN).fadeIn(500);});
			nownow += 1;

		}else{
			NN = 0;
			$('#slides li').eq(nownow).css('z-index','900');
			$('#slides li').eq(NN).stop(true,true).css({'z-index':'800'}).show();
			$('#slides li').eq(nownow).fadeOut(400,function(){$('#slides li').eq(0).fadeIn(500);});
			pagination.eq(NN).addClass('current').siblings('li').removeClass('current');

			nownow=0;

			}
		}
		TT = setTimeout(GOGO, SPEED);
	}
	
	TT = setTimeout(GOGO, SPEED); 

})