本文章接上面的方法来实例一款用于商城比较好看点儿 图片切换效果代码,有需要了解的朋友可参考。
代码如下
复制代码
<script type=“text/javascript” src=“../jquery.js”></script>
<script type=“text/javascript” src=“../dgallery.js”></script>
<script>
//这东西 基本与DPica 基本一样 不同的是 他着重注重了CSS 样式 因为按钮背景透明与文字不透明 这里要加倍注意 基本上方法是一样的
function DPicb(){
DGallery.call( this ); //继承
var btn_container, font; //按钮背景 与 文字
var mybtn = new Array(); //按钮对象列表
var self = this;
this._init = this.init; //继承构造方法
this.init = function( opt ){//构造方法
this._init( opt )
//生成按钮 begin
var title = this.getTitles();
btn_container = $(‘<ul class=“dpicb-list”></ul>’).appendTo( this.getContainer() );
for( var i = 0; i < this.len(); i ++ ){
var t = $(‘<li>’).appendTo( btn_container ).attr( ‘index’, i );
var a = $(‘<a href=“javascript:void(0);”></a>’).html( title[i] != null ? title[i] : ( i + 1 ) ).appendTo( t )
var s = $(‘<span>’).appendTo( t );
t.hover(function(){
var me = $(this);
self.stop();
self.show( parseInt( me.attr( ‘index’ ) ) );
focus( me );
}, function(){
self.play();
});
mybtn.push( t );
}
//生成按钮 end
focus( mybtn[0] );
}
//按钮变色
var focus = function( btn ){
for( var i = 0; i < mybtn.length; i ++ ) mybtn[i].removeClass( ‘focus’ );
btn.addClass( ‘focus’ );
}
//设置
this.setDefault({
‘play’ : ‘auto’,
‘effect’ : ‘fade’,
‘before’ : function(){
var cur = this.getNext();
focus( mybtn[cur] );
}
})
//必须滴
return this.jready( arguments );
}
//样式
document.write( ‘<style>’ );
document.write( ‘.dpicb-list{width:100000px;height:25px;list-style:none;position:absolute;z-index:999;bottom:0;margin:0;padding:0;}’ );
document.write( ‘.dpicb-list li{width:182px;height:25px;display:block;float:left;text-align:center;line-height:30px;margin:0;padding:0;margin-right:1px;}’ );
document.write( ‘.dpicb-list li span{width:182px;height:25px;display:block;background-color:#000;filter:alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;}’ );
document.write( ‘.dpicb-list li a{width:182px;height:25px;display:block;position:absolute;z-index:999;line-height:25px;text-decoration:none;font-size:12px;color:#FFF;}’)
document.write( ‘.dpicb-list li.focus span{background-color:#D50563;}’ );
document.write( ‘.dpicb-list li.focus a{background:url(../panel/type0.gif) no-repeat center bottom;}’ );
document.write( ‘</style>’ );
new DPicb(‘#pic7′, ’7_1.png|7_4.jpg|7_3.jpg|7_6.jpg’, ‘../image/’, ‘link3|link4|link5|link6′, ‘限时特卖|会员拼购|VIP专场|积分换购’ );
</script>
<body>
<div id=“pic7″ style=“width:733px;height:330px;margin:100px auto; position:relative;”></div>
</body>