【问题标题】:Add a button to change background添加一个按钮来改变背景
【发布时间】:2012-11-23 13:02:34
【问题描述】:

我有 Fancybox v2 的画廊。我想在不同的背景下观看。在打开的图片上,我想放置三个按钮,可以更改外部背景。 是否可以实施? 感谢您的任何帮助和建议。

【问题讨论】:

    标签: jquery css fancybox-2


    【解决方案1】:

    这完全取决于您使用的选择器。 $(body).css({'background-image' : 'url(...your url here)'}) 将更改正文图像。 如此完整的代码:

    <style>
        body{
            background-image:url(image%20here);
        }
    </style>
    <script>
        $(document).ready(function(){
            $('#button1').click(function(){
                $(body).css({'background-image' : 'url("new%20image%20here")'});
            }
            /*alternative way*/
            $('#button2').click(function(){
                var url = 'new%20url%20one');
                changeBody(url);
            });
            $('#button3').click(function(){
                var url = 'new%20url%20two');
                changeBody(url);
            });
        });
        changeBody(url){
            $(body).css({'background-image' : url});
        }
    <script>
    </head>
    <body>
        <button id="button1">Change 1</button></br>
        <button id="button2">Change 2</button></br>
        <button id="button3">Change 3</button></br>
    </body>
    

    【讨论】:

    • 谢谢。我有一个类似的代码。但我需要在 Fancybox v2 中使用它。我忘了指定它。有谁知道如何在fancybox中实现这一点?
    • 对不起,我尽量不使用插件。试着看看花哨的盒子尺寸是怎么做的。
    猜你喜欢
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多