jquery 主题设置选项

发布于 2024-09-29 10:20:51 字数 720 浏览 3 评论 0原文

创建这个主题时,我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笏见 2024-10-06 10:20:51

按照您现在设置插件的方式,slideShowShadow.css 尝试在加载时分配 slideshow.opacity,并且超出 themeSettings 的范围code> 函数,这意味着 slideshow.opacity 将为 undefined。您所要做的就是将最后几行移到 themeSettings 函数中,以便当您通过调用 $('#your_elem').themeSettings 将插件应用到某个元素时运行它们()

(function($){
  $.fn.themeSettings = function(options) {

    var slideshow = {
          opacity: '0.5'
        },
        settings = $.extend({}, slideshow, options),
        slideShowShadow = $('#slideShadowTop, #slideShadowBottom, #slideShadowLeft, #slideShadowRight');

    slideShowShadow.css({ 
      opacity: settings.opacity 
    });
  };
})(jQuery);

注意:您的原始帖子在 $.extend 函数中引用了一个未定义的变量(default),我确信您本来打算将其作为slideshow 对象。

The way you have the plugin set up right now, slideShowShadow.css is trying to assign slideshow.opacity at loading time and outside the scope of the themeSettings function, which means that slideshow.opacity will be undefined. All you have to do is move the last few lines into the themeSettings function so that they're run when you apply the plugin to some element by calling $('#your_elem').themeSettings():

(function($){
  $.fn.themeSettings = function(options) {

    var slideshow = {
          opacity: '0.5'
        },
        settings = $.extend({}, slideshow, options),
        slideShowShadow = $('#slideShadowTop, #slideShadowBottom, #slideShadowLeft, #slideShadowRight');

    slideShowShadow.css({ 
      opacity: settings.opacity 
    });
  };
})(jQuery);

Note: Your original post referenced an undefined variable (default) in the $.extend function, which I'm sure you had intended to be the slideshow object.

2024-10-06 10:20:51
$(function(){

        var slideshow = {  
                opacity: 1,
                corners: true,
                shadows: true
        },
            xShadow = {
                opacity: 0.5      
        }; 

        // Slideshow Corners & Shadows        
        var $hWrap = $('#headerTopWrapper');

        if(slideshow.corners){
            $hWrap.prepend('<div id="slideCornersTop"></div>' + "\n" +
                           '<div id="slideCornersBottom"></div>');   
        }

        if(slideshow.shadows){
            $hWrap.prepend('<div id="slideShadowTop"></div>' + "\n" +
                           '<div id="slideShadowBottom"></div>' + "\n" +
                           '<div id="slideShadowRight"></div>' + "\n" +
                           '<div id="slideShadowLeft"></div>'); 
        }


        // Slideshow Shadow Opacity
        var $slideShowShadow = $('#slideShadowTop, #slideShadowBottom, #slideShadowLeft, #slideShadowRight');

        $slideShowShadow.css({
            opacity: xShadow.opacity
        });

});
$(function(){

        var slideshow = {  
                opacity: 1,
                corners: true,
                shadows: true
        },
            xShadow = {
                opacity: 0.5      
        }; 

        // Slideshow Corners & Shadows        
        var $hWrap = $('#headerTopWrapper');

        if(slideshow.corners){
            $hWrap.prepend('<div id="slideCornersTop"></div>' + "\n" +
                           '<div id="slideCornersBottom"></div>');   
        }

        if(slideshow.shadows){
            $hWrap.prepend('<div id="slideShadowTop"></div>' + "\n" +
                           '<div id="slideShadowBottom"></div>' + "\n" +
                           '<div id="slideShadowRight"></div>' + "\n" +
                           '<div id="slideShadowLeft"></div>'); 
        }


        // Slideshow Shadow Opacity
        var $slideShowShadow = $('#slideShadowTop, #slideShadowBottom, #slideShadowLeft, #slideShadowRight');

        $slideShowShadow.css({
            opacity: xShadow.opacity
        });

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文