Sliderjs具有动态内容或图像

时间:2012-08-10 21:47:00

标签: javascript jquery

我正在解决一个问题,似乎无法找到答案。我使用sliderjs.com的sliderjs显然创建了一个滑块面板。该脚本适用于硬编码的html(

  • 元素在niceslideing面板中呈现)。

    现在我想用javascript动态插入那些ul,li元素。问题是如果slidejs没有正确形成新插入的代码。我做错了什么,我该怎么做才能纠正这个问题。任何帮助表示赞赏。滑动面板仅适用于手机设备......

    如果我对此进行硬编码而不是

    <div id='slider' class='swipe' style='width:150px'>
    <ul>
    <li style='display:block'><div>1</div></li>
    <li style='display:none'><div>2</div></li>
    <li style='display:none'><div>3</div></li>
    <li style='display:none'><div>4</div></li>
    <li style='display:none'><div>5</div></li>
    </ul>
    </div>
    

    这是我的完整代码,其中包含无效的javascript

     <html>
    <head>
        <title></title>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
        <meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=1;" name="viewport" />
        <style type="text/css">
            html{background-color:transparent;height:100%;width:100%;}
            body{background-color:transparent;font-size:11pt;font-family:helvetica;}
            img{border:0px;}        </style>
        <link rel="stylesheet" href="BTA_Blog_Leather_colors/brown/BTA_Blog_Leather_brown.css" type="text/css" />
        <link rel="stylesheet" href="style.css" type="text/css" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                              if ($(".date").text() === "--")
                              $(".datecontainer").hide();
                              if($('.thevideo iframe').attr('src') === ""){
                              console.log('11');
                              $(".videocontainer").hide();
                              }
    
                              var names = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/187660_100002435611825_501947_q.jpg,http://www.deerns.nl/gfx/image.phtml?image=/images/_images_2012_website/employees/Nederland/Martijn%20Timmer_DIE2082.jpg&width=50&height=50&type=crop,http://profile.ak.fbcdn.net/hprofile-ak-snc4/187660_100002435611825_501947_q.jpg";
    
    var namesArray = names.split(",");
    var item, items = [];
    
    for (var i = 0; i < namesArray.length; i++) {
        item = {};
        item.name = namesArray[i];
        items.push(item);
    }
    
    var main = $("<ul>");
    var str = "<li style='display:block;'><div><img src='http://profile.ak.fbcdn.net/hprofile-ak-snc4/187660_100002435611825_501947_q.jpg' /></div></li>";
    for (var i = 0; i < items.length; i++) {
        str += "<li style='display:none;'><div><img src='" + items[i].name + "' /></div></li></ul>";
    
    }
    main.html(str);
            $('#slider').append(main);
    
                              });
            </script>
    </head>
    <body>
        <div id="container">
            <div class="navbar">
                <div class="titlebox">
                    <div class="title">Gaat Europa het redden met de Euro? en met weet ik wat nog allemaal</div>
                </div><!-- end titlebox -->
            </div><!-- end navbar -->
            <div id="body">
                <div class="header">
                    <div class="theimage">
                        <div class="imagecontainer">
                            <div class="image"><!-- <img src="http://www.celfoon.nl/bt-addons/testimage130x130.png" /> -->
                                <div class="datecontainer">
                                    <div class="monthcontainer">
                                        <div class="dmonth">[[DATEMONTH]]
                                        </div> <!-- en monthcontainer -->
                                        <div class="daycontainer">
                                            <div class="dday">[[DATEDAY]]
                                            </div><!-- end daycontainer -->
                                            <div class="yearcontainer">
                                                <div class="dyear">[[DATEYEAR]]
                                                </div> <!-- end yearcontainer -->
                                            </div>
                                        </div>
                                    </div>
                                </div><!-- end datecontainer -->
                            </div>
                        </div>
                    </div><!--end theimage -->
                </div><!-- end header -->   
                <div class="content">
    
                    <div class="introtextcontainer">
                        <div class="introtext">
            <div id='slider' class='swipe'>
    
    </div>
    <a href='#' onclick='slider.prev();return false;'>prev</a>
    <a href='#' onclick='slider.next();return false;'>next</a>
    <br><br>
                        </div>
                    </div>
                    <div class="fulltextcontainer">
                        <div class="fulltext">
                            [[FULLTEXT]]
                        </div><!--end fulltext-->
                    </div><!--end fulltextcontainer-->
    
    
                    <div class="videocontainer">
                        <div class="thevideo">
                            <iframe allowfullscreen="" frameborder="0" height="174" src="[[YOUTUBE]]" width="280"></iframe>
                        </div><!-- end videocontainer -->
                    </div><!-- end thevideo -->                 
                </div><!-- end content -->
            </div><!-- end body -->
            <div id="footer">
                <div class="footertextcontainer">
                    <div class="footertext">[[FOOTERTEXT]]
    
                    </div>
    
                </div>
            </div>
        </div><!-- end container -->
        <script src='swipe.js'></script>
    <script>
    new Swipe(document.getElementById('slider'));
    new Swipe(document.getElementById('slider2'));
    var slider = new Swipe(document.getElementById('slider'));
    var slider3 = new Swipe(document.getElementById('slider3'));
    var slider4 = new Swipe(document.getElementById('slider4'));
    </script>
    </body>
    </html>
    
  • 0 个答案:

    没有答案