- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Superfish JS 是 here .
相关代码如下:
$.fn.extend({
hideSuperfishUl : function() {
// ...code here...
return this;
},
showSuperfishUl : function(){
// ...code here...
return this;
}
});
问题:
$.fn.extend({...});
是否允许用户覆盖 hideSuperfishUl
和 showSuperfishUl
函数?如果是这样,调用插件时更改这些方法的语法是什么样的:
<script>
$(document).ready(function() {
$('ul.sf-menu').superfish(); // How to override hideSuperfishUl &/or showSuperfishUl?
});
</script>
Superfish 是不久前编写的...这仍然是允许用户覆盖插件功能功能/方法/其他的最佳方式吗?如果没有,有没有“最好”的方法?
最佳答案
尝试在这里回答我自己的问题...如果我在下面写的任何内容有误,请纠正我!;)
<小时/>This article说的是:
Extend
In my opinion, this is the least idiomatic way to create a jQuery plugin. It uses the
jQuery.fn.extend
method instead ofjQuery.fn.pluginName
:(function($){
$.fn.extend({
myPlugin: function() {
return this.each(function(){
// do something
});
},
myOtherPlugin: function() {
return this.each(function() {
// do something
});
}
});
})(jQuery);You will find this structure helpful if you need to add a large number of plugin methods to jQuery. I would contend, however, that if your plugin needs to add that many methods, there may be a better way to structure its implementation.
I feel the extend method is used more by programmers transitioning from other JS libraries. I personally find the simple
$.fn.pluginName
structure to be easier to read, and more in line with what you will normally see in jQuery plugins.
=
Superfish JS 使用与上面引用中相同的代码;长话短说,showSuperfishUl()
和 hideSuperfishUl()
是 jQuery $.fn
命名空间中的附加插件。
我能够像这样覆盖所述函数:
jQuery(function(){
$.fn.showSuperfishUl = function() {
console.log('OMG');
return this;
};
$.fn.hideSuperfishUl = function() {
console.log('BECKY');
return this;
};
jQuery('ul.sf-menu').superfish();
});
下一步,this article说:
Provide public access to secondary functions as applicable
// plugin definition
$.fn.hilight = function(options) {
// iterate and reformat each matched element
return this.each(function() {
var $this = $(this);
// ...
var markup = $this.html();
// call our format function
markup = $.fn.hilight.format(markup);
$this.html(markup);
});
};
// define our format function
$.fn.hilight.format = function(txt) {
return '<strong>' + txt + '</strong>';
};We could have just as easily supported another property on the options object that allowed a callback function to be provided to override the default formatting. That's another excellent way to support customization of your plugin. The technique shown here takes this a step further by actually exposing the format function so that it can be redefined. With this technique it would be possible for others to ship their own custom overrides of your plugin נin other words, it means others can write plugins for your plugin.
$.fn.extend
和 $.fn.pluginName.function
相似,允许最终用户轻松覆盖功能;前者将新插件添加到 jQuery $.fn
命名空间,而后者是包含在单个 $.fn.pluginName
命名空间中的函数。
Don't clutter the jQuery.fn object with more than one namespace per plugin.
...因此,我选择的“最佳”技术是 $.fn.pluginName.function
。
关于jquery - Superfish 插件 : $. fn.extend({...}) -- 这段代码是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11286312/
我的 superfish 下拉菜单有问题 - 在我将 jQuery.Columnizer 添加到我的项目之前它工作正常。取出列生成器 jQuery 修复了 superfish.js 的问题 - 然而,
我知道 superfish 很神奇,但是我们使用的可怕的 CMS 在 IE6 中与它发生冲突(当 CMS 将选定的类应用于 li 时,在 IE6 中悬停会中断)。我不知道怎么做,但请随意查看valit
我在 jQuery 网格中使用 Superfish 下拉菜单时遇到问题。看起来下拉列表被表格边界限制了。 我已经研究过了,这似乎是一个 z-index 问题,除了我尝试了 z-index 的各种组合都
查看链接: http://www.advertisesolutions.com/beta/4kitchens.html 无法理解为什么主菜单和子菜单下方有空隙,Profile->Profile Set
我一直在为我的非营利组织网站工作,试图将我们冗长的下拉菜单放入两列,但收效甚微。我已经加宽了 UL 并将 LI 元素的宽度设置为 50%,但是我在较长的元素上出现了较大的白色间隙。我看过的教程结构要简
我试图将子菜单项中的文本对齐到右侧而不是 Superfish 菜单中的左侧。 我能够将下拉菜单对齐到顶级菜单项的右侧,但似乎无法确定文本对齐方式。 此外,我将如何让更多的子菜单向左而不是向右打开?由于
我已经用我的 wordpress 菜单设置了 Superfish。我设法让它工作正常。但是我已经按照此处的文档进行操作: http://users.tpg.com.au/j_birch/plugins
我正在尝试垂直使用 Superfish,但与页面右侧对齐,从而打开左侧的所有子菜单。我一直在调整一些 CSS 属性来实现这一点,但它并不能完美地工作——箭头总是位于任何父菜单文本的右侧,而在这种情况下
我一直在与一位客户合作,为他们的 dentry 公司建立一个新网站。开发站点的链接在这里:http://virtualiellc.com/skd/ 我最近注意到页面底部有一个水平滚动条,而本不该有的。
我遇到了一个 CSS 问题,我的带有子菜单的菜单与没有子菜单的菜单的缩进方式不同。我已经尝试了一些来自谷歌的解决方案但没有成功。 例如,如果您访问我们的网站并将鼠标悬停在“drinkware”上,您会
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
以前有人问过这个问题,但我只能找到 Superfish 的弃用版本的修复/破解. 如果缩小屏幕,您可以看到嵌套/子列表呈现在屏幕外。是否可以修复此缺点,使子菜单显示在左侧而不是右侧,或者以某种方式识别
如何更改 superfish 菜单中每个按钮之间的间距?我正在使用垂直菜单 css。 最佳答案 如果您正在寻找的是将 Superfish 下拉菜单第一级的元素隔开,只需为 .sf-menu 容器的直接
我正在尝试配置 superfish 以我想要的方式显示。到目前为止一切看起来都不错,只是我希望菜单正确对齐。这也有效,但现在我所有的菜单项都被镜像了,所以不再是我想要的顺序...... 看看:http
根据我初始化 Superfish 的方式,我会在悬停时看到箭头或子菜单,但不会同时出现。 箭头将显示为:(但没有子菜单) jQuery(document).ready(function(){
我正在使用 Superfish 开发一个网站,但遇到了一个我无法解决的恼人问题。 基本上,除非您将鼠标悬停在带有子菜单的菜单项上,否则菜单看起来不错。我启用了箭头以指示何时有子菜单,但是当您将鼠标悬停
我正在尝试从 Superfish 自定义导航栏这样它就会在屏幕中央并拉伸(stretch)到宽度的 100%。但我所做的每一次尝试都会导致 li 元素拉伸(stretch)以适应 100% 的屏幕。
我试图让我的 superfish js 菜单上的子菜单全部对齐到顶部,而不是从父 li 中弹出。我试过这个解决方案: How to get superfish sub menus top-aligne
我正在使用 Superfish 在网站上显示水平菜单。每当我在当前菜单项或子菜单项的页面上时,子菜单总是显示。发生这种情况时,当您将鼠标悬停在其他子菜单上时,它会与其他子菜单重叠。如何隐藏当前显示的子
当我点击一个按钮时, super 鱼不会像我想要的那样改变颜色。HTML: Home Products
我是一名优秀的程序员,十分优秀!