而所封装的代码如下

Heim  >  Artikel  >  Web-Frontend  >  jquery.boxy弹出框(后隔N秒后自动隐藏/自动跳转)_jquery

jquery.boxy弹出框(后隔N秒后自动隐藏/自动跳转)_jquery

WBOY
WBOYOriginal
2016-05-16 17:43:311125Durchsuche

对于 Boxy弹出框的使用之前写过一些文章(查看jquery.boxy基础),今天主要是在解决一个需要之后,觉得值得把它记录下来,所以就再写一篇,主要功能是,在弹出对话框后,隔N秒后自动隐藏,还有就是自动跳转!

效果如图
jquery.boxy弹出框(后隔N秒后自动隐藏/自动跳转)_jquery 
而所封装的代码如下

复制代码 代码如下:

// boxy对话框扩展
var Boxy_Extensions = {
options: {
title: '艺吧提示',
closeText: 'x'
},
//弹出后N秒后隐藏
alertDelayFun: function (info, timer, options) {
options = $.extend(this.options, options || {});
new Boxy("
" + info + "
", $.extend({ behaviours: function () {
setTimeout('$(".boxy-wrapper").hide();', timer);
}
}, options));
},
//弹出后,自动跳转
alertHrefFun: function (info, href, options) {
options = $.extend(this.options, options || {});
new Boxy("
" + info + "
", $.extend({ behaviours: function () {
location.href = href;
}
}, options));
}
}

因为options属性是公用的,所以把它提了出现,而每个方法有自己的options,如果在调用自己方法时传递了options,通过$.extend会把它

与类中options属性的内容进行合并(覆盖相关键的值,扩展新的键值),看来写JS也应该遵循面向对象的原则呀,呵呵!
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn