ExtJS画像ビューア(推奨)
Extjs Image Viewer
1、レンダリング
2、この例は http://yourgame.iteye.com/blog/477600 根拠に基づいて改善および修正します。
3、jsコード
Jsコード
- どこimage_window =新着Ext.Window({
- id:「画像ウィンドウ」、
- 題名 :「画像ビューア」、
- 幅:750、
- 高さ:500、
- サイズ変更可能:false、
- closeAction:'隠す'、
- レイアウト:'境界'、
- アイテム:[{
- xtype:'パネル'、
- 領域:'センター'、
- レイアウト:'フィット'、
- ボディスタイル :'background-color:#E5E3DF'、
- フレーム:false、
- 境界:false、
- html:''
- +''
- +''
- +''
- +''
- +' '
- }]、
- ボタン:[{
- テキスト:'キャンセル'、
- ハンドラ:関数(){
- image_window.hide()
- }
- }]、
- リスナー:{
- '公演':関数(c){
- pageInit()
- }
- }
- })
- / **
- *初期化
- * /
- 関数pageInit(){
- どこ画像= Ext.get(「ビューイメージ」)。
- もし(画像!=ヌル){
- Ext.get(「ビューイメージ」)。オン({
- 「マウスダウン」:{fn:関数(){この.setStyle('カーソル'、'url(images / closedhand_8_8.cur)、default')}、scope:image}、
- 「マウス」:{fn:関数(){この.setStyle('カーソル'、'url(images / openhand_8_8.cur)、move')}、scope:image}、
- 'dblclick':{fn:関数(){
- ズーム(画像、true、1.2)
- }
- }})
- 新着Ext.dd.DD(画像、「pic」)。
- //image.center()//画像を中央に配置
- //元のサイズを取得します
- image.osize = {
- width:image.getWidth()、
- 高さ:image.getHeight()
- }
- Ext.get('アップ')。オン('クリック'、関数(){imageMove('アップ'、画像)})//上に移動
- Ext.get('ダウン')。オン('クリック'、関数(){imageMove('ダウン'、画像)})// 下に移動
- Ext.get('左')。オン('クリック'、関数(){imageMove('左'、画像)})//左方移動
- Ext.get('正しい')。オン('クリック'、関数(){imageMove('正しい'、画像)})//右に移動
- Ext.get('に')。オン('クリック'、関数(){ズーム(画像、true、1.5)})//ズームイン
- Ext.get('でる')。オン('クリック'、関数(){ズーム(画像、false、1.5)})//削減
- Ext.get('ズーム')。オン('クリック'、関数(){復元(画像)})//戻す
- }
- }
- / **
- *画像の移動
- * /
- 関数imageMove(direction、el){
- el.move(方向、50、true)。
- }
- / **
- *
- * @param elpictureオブジェクト
- * @param type trueズームイン、falseズームアウト
- * @ paramオフセット量
- * /
- 関数ズーム(el、type、offset){
- どこwidth = el.getWidth()
- どこ高さ= el.getHeight()
- どこnwidth =タイプ? (幅*オフセット):(幅/オフセット)
- どこnheight =タイプ? (高さ*オフセット):(高さ/オフセット)
- どこ左=タイプ? -((nwidth-width)/ 2):((width-nwidth)/ 2)
- どこトップ=タイプ? -((nheight-height)/ 2):((height-nheight)/ 2)
- el.animate(
- {{
- 高さ:{to:nheight、from:height}、
- 幅:{to:nwidth、from:width}、
- 左:{by:left}、
- top:{by:top}
- }、
- ヌル、
- ヌル、
- 'backBoth'、
- 'モーション'
- )。
- }
- / **
- *画像の復元
- * /
- 関数復元(el){
- どこサイズ= el.osize
- //カスタムコールバック関数
- 関数センター(el、コールバック){
- el.center()
- コールバック(the)
- }
- el.fadeOut({コールバック:関数(){
- el.setSize(size.width、size.height、{コールバック:関数(){
- センター(、、関数(ee){//コールバック
- ee.fadeIn()
- })
- }})
- }
- })
- }
var image_window = new Ext.Window({ id: 'image-window', Title : 'picture browsing', width : 750, height : 500, resizable : false, closeAction :'hide', layout:'border', items:[{ xtype: 'panel', region: 'center', layout:'fit', bodyStyle : 'background-color:#E5E3DF', frame:false, border:false, html :' ' +' ' +' ' +' ' +' ' +' ' }], buttons: [{ Text: 'cancel', handler: function() { image_window.hide() } }], listeners: { 'show': function(c) { pageInit() } } }) /** * Initialization */ function pageInit(){ var image = Ext.get('view-image') if(image!=null){ Ext.get('view-image').on({ 'mousedown':{fn:function(){this.setStyle('cursor','url(images/closedhand_8_8.cur),default')},scope:image}, 'mouseup':{fn:function(){this.setStyle('cursor','url(images/openhand_8_8.cur),move')},scope:image}, 'dblclick':{fn:function(){ zoom(image,true,1.2) } }}) new Ext.dd.DD(image, 'pic') //image.center()//Image centered / / Get the original size image.osize = { width:image.getWidth(), height:image.getHeight() } Ext.get('up').on('click',function(){imageMove('up',image)}) //Move up Ext.get('down').on('click',function(){imageMove('down',image)}) //Move down Ext.get('left').on('click',function(){imageMove('left',image)}) //Shift left Ext.get('right').on('click',function(){imageMove('right',image)}) //Right to move Ext.get('in').on('click',function(){zoom(image,true,1.5)}) //Zoom in Ext.get('out').on('click',function(){zoom(image,false,1.5)}) //Zoom out Ext.get('zoom').on('click',function(){restore(image)}) //Restore } } /** * Picture move */ function imageMove(direction, el) { el.move(direction, 50, true) } /** * * @param el picture object * @param type true zoom in, false zoom out * @param offset amount */ function zoom(el,type,offset){ 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' ) } /** * Picture restoration */ function restore(el) { var size = el.osize / / Custom callback function function center(el,callback){ el.center() callback(el) } el.fadeOut({callback:function(){ el.setSize(size.width, size.height, {callback:function(){ Center(el,function(ee){//call callback ee.fadeIn() }) }}) } }) }
4、フォームjsを呼び出します
Jsコード- image_window.show()
- image_window.setTitle(「画像プレビュー-」+ array [0] .pigCode +'['+ picType +']')。
- Ext.get(「ビューイメージ」).dom.src ='upload /'+ array [0] .picName
image_window.show() image_window.setTitle('image preview-' + array[0].pigCode + '[' + picType + ']') Ext.get('view-image').dom.src = 'upload/' + array[0].picName
注:フォームは、srcを画像アドレスにポイントするだけで、プログラムのどこからでも直接呼び出すことができます。
5、他のcssと画像はアドレスから使用できます: http://yourgame.iteye.com/blog/477600 ダウンロード