jquery 主题设置选项
创建这个主题时,我对 jquery 很陌生,并且像往常一样挣扎。
刚刚观看了本教程,并决定尝试制作自己的主题设置以简化自定义。
这就是我到目前为止所拥有的:
(function($){
$.fn.themeSettings = function(options) {
var
slideshow = {
opacity: '0.5'
},
settings = $.extend({}, defaults, options);
};
var slideShowShadow = $('#slideShadowTop, #slideShadowBottom, #slideShadowLeft, #slideShadowRight');
slideShowShadow.css({
opacity: slideshow.opacity
});
})(jQuery);
任何帮助都会很棒,因为它搞乱了我还没有添加到主题中的当前 jquery。
我认为通过代码你可以看到我想要完成什么,但显然因为我是 jQuery 的新手,我不知道如何去做。
任何帮助将不胜感激,干杯
Creating this theme, I'm pretty new to jquery and struggling as usual.
Just watched this tutorial and decided to have a shot at making my own theme settings to simplify customization.
This is what i have so far:
(function($){
$.fn.themeSettings = function(options) {
var
slideshow = {
opacity: '0.5'
},
settings = $.extend({}, defaults, options);
};
var slideShowShadow = $('#slideShadowTop, #slideShadowBottom, #slideShadowLeft, #slideShadowRight');
slideShowShadow.css({
opacity: slideshow.opacity
});
})(jQuery);
Any help would be awesome since It's messing up all over current jquery on the theme which I have not added to it yet.
I think by the code you can see what I'm trying to accomplish but obviously since I'm new to jQuery I'm not sure how to go about it.
Any help would be much appreciated, cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按照您现在设置插件的方式,
slideShowShadow.css
尝试在加载时分配slideshow.opacity
,并且超出themeSettings
的范围code> 函数,这意味着slideshow.opacity
将为undefined
。您所要做的就是将最后几行移到themeSettings
函数中,以便当您通过调用$('#your_elem').themeSettings 将插件应用到某个元素时运行它们()
:注意:您的原始帖子在
$.extend
函数中引用了一个未定义的变量(default
),我确信您本来打算将其作为slideshow
对象。The way you have the plugin set up right now,
slideShowShadow.css
is trying to assignslideshow.opacity
at loading time and outside the scope of thethemeSettings
function, which means thatslideshow.opacity
will beundefined
. All you have to do is move the last few lines into thethemeSettings
function so that they're run when you apply the plugin to some element by calling$('#your_elem').themeSettings()
:Note: Your original post referenced an undefined variable (
default
) in the$.extend
function, which I'm sure you had intended to be theslideshow
object.