extjs继承panel实现图片缩放、翻页功能

Ext.onReady(function() {
ImgView = Ext.extend(Ext.Panel, {
height: 740,
img_index: 0,
img_view_id: this.id + '_img',

set_img: function(offset) {
Ext.get(this.img_view_id).dom.src = this.src[this.img_index + offset];
Ext.getCmp(this.id + '_next_btn').disabled = ((this.img_index + offset) == this.src.length - 1) ? true : false;
Ext.getCmp(this.id + '_pre_btn').disabled = ((this.img_index + offset) == 0) ? true : false;
this.img_index = this.img_index + offset;
},
initComponent: function(){
var cmp = this;
this.html='<img id=\'' + this.img_view_id + '\' src=\'' + this.src[0] + '\' ></img>';
this.tbar = [
{text:"上一张", id: this.id + '_pre_btn', handler: function(){

cmp.set_img(-1);
}},
{text:"下一张", id: this.id + '_next_btn', handler: function(){
cmp.set_img(1);
}}];

ImgView.superclass.initComponent.call(this);
},
afterRender: function() {
ImgView.superclass.afterRender.call(this);
Ext.get(this.img_view_id).parent = this;
Ext.get(this.img_view_id).center();
new Ext.dd.DD(Ext.get(this.img_view_id), 'pic');
//Ext.get(this.img_view_id).dom.title='双击放大 右击缩小';
Ext.get(this.img_view_id).on({
'dblclick': {fn: function(){
Ext.get(this).parent.zoom(Ext.get(this), 1.5,true);
}},
'contextmenu': {fn: function(){
Ext.get(this).parent.zoom(Ext.get(this), 1.5,false);
}}
});
},
//放大、缩小
zoom: function(el, offset,type) {
var width = el.getWidth();
var height = el.getHeight();
var nwidth = type ? (width * offset) : (width / offset);
var nheight = type ? (height * offset) : (height / offset);
var left = type ? -((nwidth - width) / 2):((width - nwidth) / 2);
var top = type ? -((nheight - height) / 2):((height - nheight) / 2);
el.animate(
{
height: {to: nheight, from: height},
width: {to: nwidth, from: width},
left: {by:left},
top: {by:top}
},
null,
null,
'backBoth',
'motion'
);
}
});
var img1 = new ImgView({src: ['img_file/001.jpg','img_file/002.jpg','img_file/003.jpg','img_file/004.jpg'], title: '图片浏览'});
var main_panel = new Ext.Panel({
title: 'main_panel',
el: 'main_panel',
autoHeight: true,
bodyBorder: false,
collapsible: true,
renderTo: Ext.getBody(),
items: [img1]
});
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值