Javascript 单击可切换可扩展背景

Javascript 单击可切换可扩展背景,javascript,jquery,Javascript,Jquery,我想创建一个链接;例如“点击这里进行背景演示”。然后点击链接;然后,网页的背景会显示一幅图像,该图像可以展开 我有一个独立的可扩展背景解决方案;使用下面的方法 但我怎么能只显示“点击”呢;实施 <!--Expandable BG code IE 7 +--> <style> #bg { position: fixed; top: 0; left: 0; } .bgwidth { width: 100%

我想创建一个链接;例如“点击这里进行背景演示”。然后点击链接;然后,网页的背景会显示一幅图像,该图像可以展开

我有一个独立的可扩展背景解决方案;使用下面的方法

但我怎么能只显示“点击”呢;实施

<!--Expandable BG code IE 7 +-->

  <style>

                #bg { position: fixed; top: 0; left: 0; }
                .bgwidth { width: 100%; }
                .bgheight { height: 100%; }

                #page-wrap { position: relative; width: 950px; margin-left: auto; margin-right: auto;;  }

  </style> 


 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <script>
                $(function() {   
                        var theWindow        = $(window),
                            $bg              = $("#bg"),
                            aspectRatio      = $bg.width() / $bg.height();

                        function resizeBg() {

                                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                                    $bg
                                        .removeClass()
                                        .addClass('bgheight');
                                } else {
                                    $bg
                                        .removeClass()
                                        .addClass('bgwidth');
                                }

                        }

                        theWindow.resize(function() {
                                resizeBg();
                        }).trigger("resize");

                });
        </script>


<!--Expandable BG code IE 7 +-->

#bg{位置:固定;顶部:0;左侧:0;}
.bgwidth{width:100%;}
.bgheight{高度:100%;}
#换页{位置:相对;宽度:950px;左边距:自动;右边距:自动;;}
$(函数(){
var theWindow=$(窗口),
$bg=$(“#bg”),
aspectRatio=$bg.width()/$bg.height();
函数resizeBg(){
如果((theWindow.width()/theWindow.height())
您有以下
调整大小
处理程序

theWindow.resize(function() {
    resizeBg();
}).trigger("resize");
如果您想在单击链接时调用它,那么可以使用

$('a.link').on('click', function(e){
    e.preventDefault();
    resizeBg();
});
只需将为
指定的代码放在
窗口.resiz
处理程序的后面/前面。还要确保您有一个带有class
链接的
a
标记,如

<a href="#" class="link">Click</a>

并删除
.trigger(“resize”)调整大小
处理程序中选择code>,以停止在加载时调用处理程序