/* 缺陷,當前在ff3下,用jquery的 width()與height()函數,在不設置圖片的寬度與高度的時候,不能取到 需要在圖片load函數裏面初始化纔可以 */ sanshi_imgareaselect = function(pic_id,view_div_id){ this.pic_obj = jQuery("#"+pic_id); this.pic_width; this.pic_height; this.view_div_id = view_div_id; this.view_width = 100; this.view_height = 100; this.view_img_id = view_div_id+"_sanshi_img"; this.ias; } //建立預覽圖片 sanshi_imgareaselect.prototype.make_view_pic =function(){ var img_obj = jQuery(document.createElement("IMG")); img_obj.attr("src",this.pic_obj.attr("src")); img_obj.attr("id",this.view_img_id); img_obj.attr("width",this.view_width); img_obj.attr("height",this.view_height); return img_obj; } //初始化函數 sanshi_imgareaselect.prototype.init=function(){ this.pic_width = this.pic_obj.attr("width"); this.pic_height = this.pic_obj.attr("height"); //alert(this.pic_width+":"+this.pic_height); //添加圖片 jQuery("#"+this.view_div_id).append(this.make_view_pic()); //設置預覽加載層樣式 jQuery("#"+this.view_div_id).css({'width':this.view_width,'height':this.view_height,'overflow':'hidden'}); //構造選擇區域完成的函數 var fun_str="if ( selection.width && selection.height){ var scaleX = "+this.view_width+" / selection.width;var scaleY = "+this.view_height+" / selection.height;jQuery('#"+this.view_img_id+"').css({width: Math.round(scaleX * "+this.pic_width+"),height: Math.round(scaleY * "+this.pic_height+"),marginLeft: -Math.round(scaleX * selection.x1),marginTop: -Math.round(scaleY * selection.y1)});}"; //alert(fun_str); //初始化imgAreaSelect 函數 var ias = this.pic_obj.imgAreaSelect({ //設置選擇框的比列 //aspectRatio:"1:1", //設置框的添加效果 fadeSpeed:200, //選擇框選擇完畢是否自己取消 autoHide:false, //是否顯示圖片遮罩層 show:true, //是否採用api instance: true, //設置初始函數 畫出選擇框 onInit:function(img, selection){ias.setSelection(100, 50, 250, 150, true);ias.update();}, //設置選擇完畢的函數,採用了動態執行 onSelectEnd:function(img, selection){eval(fun_str);} }); //賦值給全局 this.ias = ias; } //保存事件 採用的是get方式提交 sanshi_imgareaselect.prototype.save_pic=function(post_page,post_param){ var opt = this.ias.getSelection(true); var post_arr = new Array(); jQuery.each(post_param,function(i,n){ var temp_str =i+"="; temp_str += opt[n] ? opt[n] : n; post_arr.push(temp_str); }); //判斷,是否有參數 post_page += post_page.lastIndexOf("?")<0 ? "?" : "&"; //拼裝get方式的url post_url = post_page+post_arr.join("&"); alert(post_url); }
這個是封裝後js代碼
下面看看這段代碼如何使用
$(document).ready(function () { //聲明函數 var sanshi_img = new sanshi_imgareaselect("mypic","preview"); //確保圖片加載完成執行初始化函數,這樣避免上面的提到的bug,否則不能保證兼容性 $("#mypic").load(function(){sanshi_img.init();}); //監聽保存事件 $("#save_pic").click(function(){ sanshi_img.save_pic('1.php?n=6',{"id":5,"px1":"x1","py1":"y1",'px2':"x2","py2":"y2",'pwidth':"width",'pheight':"height"}); }); })
下面看下html代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="css/imgareaselect-animated.css" mce_href="css/imgareaselect-animated.css" /> <mce:script type="text/javascript" src="jquery-1.3.2.min.js" mce_src="jquery-1.3.2.min.js"></mce:script> <mce:script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js" mce_src="scripts/jquery.imgareaselect.pack.js"></mce:script> </head> <body> <div id="s"> <img id="mypic" name="mypic" dt="sanshi" src="scott-h-biram.jpg" mce_src="scott-h-biram.jpg" title="mypic"/> </div> <div id="preview"></div> <div><input type="button" id="save_pic" value="保存"></div> </body> </html>
這裏面的html的頭式不能丟的,如果丟了,會在ie7下有問題,不影響使用,但是影響美觀度
採用jquery封裝
(function($){ $.fn.sanshi_imgareaselect=function(view_div_id){ var sanshi_img = new sanshi_imgareaselect($(this).get(0),view_div_id); $(this).load(function(){sanshi_img.init();}); return sanshi_img; } })(jQuery) $(document).ready(function () { var pic_obj = $("#mypic").sanshi_imgareaselect("preview"); $("#save_pic").click(function(){ pic_obj.save_pic('1.php?n=6',{"id":5,"px1":"x1","py1":"y1",'px2':"x2","py2":"y2",'pwidth':"width",'pheight':"height"}); }); })
原文鏈接:https://twindy.org/http-https-socksdai-li-zhi-shi-hui-zong/ 什麼是代理? 在計算機領域,代理泛指中間傳輸web服務器,充當着用戶和目標服務器之間的中介。代理
搜索結果支持全選與取消全選,打開、搜索、隨便點 安裝vue-cli 安裝elementUI npm i element-ui -S 在main.js 引入elementUI import ElementUI from 'ele
這幾天在用vue寫項目,記錄下用vue實現tab選項卡 html <div class="tab-big white-tab-big"> <div class="tabs"> <span v-for="(item,index) in
所有html控件的值都是可以在服務器端用後臺代碼的Request[name]來獲取其值的。但如果有多個相同name的Html控件提交到後臺,怎麼分別取各個控件的值呢?而多數情況下這些控件的個數是不定的。 例如在填寫簡歷表單中,“工作
AsyncSocket簡介 在實現App的時候經常需要進行實時的網絡通信,也就是即時通信。 實現即時通信的方式很多,可以利用極光、融雲等即時通信平臺進行通信,也可以利用一些打包類進行簡單的即時通信。這些打包類也有很多,例如GCDAsyn
1、點擊“新建Item”,創建項目 2、選擇 freestyle project 3、構建觸發器-選擇Build periodically -H 10 * * * 4、構建 ubuntu選擇 Execute shell 5、命令行 /us
問題產生:由於是使用html 另存爲word導致打開生成的word文檔爲web視圖:Dispatch.call(this.document, "SaveAs", outputPath); 問題解決:1.創建空的word 文檔 this.
最近很多人提到“內卷化”這個詞,其實程序員近年來內卷化就挺嚴重的。 百度百科的搜索結果提到:內卷化,指一種社會或文化模式在某一發展階段達到一種確定的形式後,便停滯不前或無法轉化爲另一種高級模式的現象。 這一概念最早是用
這篇文章主要給大家結合微信支付接口開發的實踐,從獲取用戶授權到各主要接口的使用方法等方面介紹微信支付的關鍵點技術,有需要的小夥伴可以參考下最近做了微信公衆號支付的開發,由於是第一次做也摸索了幾天的時間,也只是達到了實現功能的水平,並沒有太
CentOS7上,JDK 1.8.0_231-b11,zookeeper-3.4.6,kafka_2.12-2.3.0 測試multi-broker的例子https://kafka.apache.org/quickstart#quicks
理論上MacBook的操作系統可以直接從WiFi重裝,但也有可能遇到網速過慢斷線等問題。如果手頭沒有別的Mac電腦,怎樣在Windows 下製作 MacOs 啓動優盤?網上有很多AppStore下載製作而來的原版dmg鏡像文件,實測這種文
UE4學習之旅(渲染篇#0001):模式下的地貌與植被的介紹 摘要 本文章主要講述如何在UE4下創建一個地形,如何使用各個地形工具以及如何快速刷出大量的植物。 地貌 在模式下點擊地貌會出現三個不同的組件。分別是管理,雕刻,描畫。
一、手動安裝Windows服務 1、使用.net framwork工具InstallUtil 該工具版本跟當前系統安裝的.net framework版本相關(路徑爲C:/Windows/Microsoft.NET/Fram
ubuntu首次登錄root密碼更改 搜索並打開Termial $sudo passwd root
一些討論 Python中使用配置文件的最佳實踐 Python中使用配置文件的最好方法 Python符號常量 多種配置文件方案對比 我的建議 1. 排除yaml yaml 不是一個好主意, 因爲需要給項目引入額外的依賴。首先排除它,除非是你