【问题标题】:Using Jquery fullscreen background plugin with multiple backgrounds on one page在一个页面上使用具有多个背景的 Jquery 全屏背景插件
【发布时间】:2012-04-20 17:58:52
【问题描述】:

我已经有一个带有左右箭头的 Jquery 滑块,用于使用锚点和散列的内容,因此所有 Web 内容(页面)都在一个 html 页面上。我需要有全屏背景,并且我使用 CSS 得到了一些工作,但它没有显示整个图像并添加了不可接受的垂直滚动条,该版本在这里: ilandeistudio.com

所以我正在尝试使用 Jquery 的不同方法: http://code.ttcon.hu/fullscrn/#!/instructions

我可以让它工作,但我不知道如何让它与滑块/多个背景一起工作。说明说您可以稍后更改背景,只需调用 setImage 方法:

fullScr.setImage("images/bg_about1.jpg");

我不确定如何执行此操作或它应该去哪里。我在这里做了一个测试页: http://www.ilandeistudio.com/index06.html

当您单击右箭头时,我希望它像在 ilandeistudio.com 发布的第一个链接上那样更改为下一个背景

【问题讨论】:

    标签: jquery background-image fullscreen


    【解决方案1】:

    无需使用 dojo 工具包或 fullscrn 插件即可完成。

    1. 将 img 放入 div,按窗口大小,固定位置,并设置 z-index:-1
    2. 使用 jQuery UI $.hide() 和 $.show() 在背景中滑入和滑出。
    3. 使用 jQuery $.attr() 更改 img src

    例子:

    <script>
    $(function() {
        i=0;j=0;
        $("#sin").click(function(event) {
            if (i = i ? 0 : 1) $("#bgimg").show("slide", { direction: "right" }, 1000);
            else $("#bgimg").hide("slide", { direction: "right" }, 1000);
        });
        $("#changebg").click(function(event) {
            bgs = ['http://www.google.com/images/srpr/logo3w.png', 'http://col.stc.s-msn.com/br/sc/i/icons/BING_websearch_2.jpg'];
            $("#bgimg").attr('src', bgs[j = j ? 0 : 1]);
        });
    });
    </script>
    <style>
    #bg{z-index:-1;position:fixed;top:0;left:0;height:100%;width:100%;}
    #bgimg{height:100%;width:100%;}
    </style>
    <button id="sin">Slide</button><button id="changebg">Change bg</button>
    
    <div id="bg"><img src="http://www.google.com/images/srpr/logo3w.png" id="bgimg" /></div>
    

    【讨论】:

    • 非常感谢您的回复,但我有点困惑。我已经有一个非常老鼠的 Jquery 插件(不是 dojo),用于使用散列/锚来调整内容。该网站只是没有显示和隐藏背景,还有文本、其他图像、整个网页 - 您可以在上面的链接中查看工作版本。我只需要知道如何使用它:fullScr.setImage("images/bg_about1.jpg");
    • @user1269988 一个可能的解决方案可能是将插件生成的背景 div 重新定位到您的滑块 div 中。您必须设置一些 CSS 属性以将其保留在您的内容后面。这是一个开始:&lt;style&gt;#fullscrn-bg{z-index:-1;position:static;top:0;left:0;height:100%;width:100%;}&lt;/style&gt;$("#fullscrn-bg").appendTo(".slider");
    【解决方案2】:

    我检查了这个 html 的提琴手。

    http://dl.dropbox.com/u/14028956/index06.html.txt

    <script type="text/javascript">
    dojo.require("dojo.NodeList-manipulate");
    dojo.require("ttcon.fullscrn");
    dojo.ready(function() {
        var fullScr = new ttcon.fullscrn({
          image: "images/bg_home1.jpg"
        });
        dojo.query(".special-anchor").onclick(function(){
          if(/home/.test(location.hash)){
            fullScr.setImage("images/bg_home1.jpg");
            return;
          }
          if(/about/.test(location.hash)){
            fullScr.setImage("images/bg_about1.jpg");
            return;
          }
        });
    });
    </script>
    

    阅读参考和文档。

    为什么要用这么多 JavaScript 库:(

    【讨论】:

    • 是的,我已经阅读了说明,但我不明白这就是我发布的原因,jquery 新手,但感谢您的回复
    • 我确实在 index06.html 测试页面上尝试过这个,但它会以白色淡入,而不是像当前解决方案那样滑动。我正在尝试添加幻灯片,不确定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    相关资源
    最近更新 更多