日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Jquery plugin template POPUP Plugin

發布時間:2024/4/17 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jquery plugin template POPUP Plugin 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以一個popup 的例子,學習怎么寫jquery插件。插件 實例化時候 包括傳屬性,函數。類似jqueryUI 的使用感覺。

實現效果類似 android 的 toast 的效果。 顯示提示消息,過幾秒后消失。

是用方法與 JQuery UI 一樣。

$('#aa').popup({
?????????????? position:{
?????????????????? x:100,
?????????????????? y:200
?????????????? },
?????????????? duration:1000,
?????????????? text:'大家好',
?????????????? hide:function(duration) {
?????????????????? console.log(this);
?????????????????? alert('fadeout duraion' + duration);
?????????????? }
?????????? });

代碼講解:

首先用jquery選擇器,選擇一個元素,來當作popup的容器。之后就是利用plugin的方法來穿參數。可以穿的參數有:

postion: popup顯示的 position坐標

duration: popup顯示的時間

text: 顯示的文字

hide: popup div 隱藏后的回調函數

?

插件代碼如下:

(function($) {
??? var methods = {
??????? init:function(options) { //初始化一個 jqueryplugin實例
??????????? return this.each(function() {
??????????????? var instance = this;? //獲取當前實例
??????????????? var isInitialized = $(instance).data("isInitialized");
??????????????? if(isInitialized == null) { //判斷是否實例化過

??????????????????? $(instance).data('options', options);

??????????????????? //給 插件對象 附加css
??????????????????? render(instance);

??????????????????? $(instance).data("isInitialized", 'true');
??????????????? }
??????????? })
??????? },

??????? show:function() {
??????????? var options = $(this).data('options'),
??????????????? duration = options.duration,
??????????????? that = this;

??????????? $(this).fadeIn(duration, function() {
??????????????? that.fadeOut(duration, function() {
??????????????????? // 給初始化時候的? hide函數 傳值
??????????????????? if(options.hide != undefined && options.hide != null) {
??????????????????????? options.hide(duration);
??????????????????? }

??????????????? });
??????????? });
??????? }
??? };

??? //private
??? var popFadeOut = function(duration) {

??????? setTimeout(function() {

??????? }, duration);

??? };

??? //private
??? var render = function(instance) {
??????? var $self = $(instance),
??????????? options = $self.data('options'),
??????????? duration = options.duration,
??????????? position = options.position,
??????????? isTop = options.isTop,
??????????? text = options.text;

??????? var cssObject = new Object();
??????? cssObject['height'] = '50px';
??????? cssObject['width'] = '200px';
??????? cssObject['position'] = 'absolute';
??????? cssObject['left'] = position.x || 300;
??????? cssObject['top'] = position.y || 100;
??????? cssObject['background'] = 'black';
??????? cssObject['color'] = 'white';
??????? cssObject['display'] = 'none';
??????? if(isTop) {
??????????? cssObject['zIndex'] = 999999;
??????? }
??????? $self.text(text);

??????? $self.css(cssObject);


??? };

??? /**
???? * popUp插件構造函數。
???? *
???? * version 1.0
???? * Author: Yuqiao Gao 3/19/2013.
???? */
??? $.fn.popup = function(method) {
??????? if(methods[method]) {
??????????? return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
??????? } else if(typeof method === 'object' || !method) {
??????????? return methods.init.apply(this, arguments);
??????? } else {
??????????? $.error('Method ' + method + ' does not exist on jquery.popup');
??????? }
??? };
})(jQuery);

轉載于:https://www.cnblogs.com/Mr-Joe/archive/2013/03/19/2969247.html

總結

以上是生活随笔為你收集整理的Jquery plugin template POPUP Plugin的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。