使用 .load() 用图像填充 div 以方便使用 slider1.7

发布于 2024-10-20 06:26:38 字数 1658 浏览 2 评论 0原文

所以我试图用外部 html 文件中的图像填充幻灯片 div,但问题似乎是新图像确实可以通过 .load() 拉取,但简单的滑块无法看到新图像,甚至只显示空白尽管在 div 中,有新的图像链接。

在我的html中,我有这个,

<script type="text/javascript" charset="utf-8">

    $(document).ready(function(){   
    $("#slider").easySlider({
    auto: true, 
    controlsFade: true,
    pause: 3000,
    continuous: false,
    numeric: true
    });
    }); 
    //]]>
    </script>

    <div id="newslideshows">
    <a href="#" id="show1"><img src="image1.jpg" /></a>
    <a href="#" id="show2"><img src="image2.jpg" /></a>
    </div>

        <div id="slider"> 
        <ul>
        <li><a href="#"><img src="1.jpg" /></a></li>
        <li><a href="#"><img src="2.jpg" /></a></li>
        </ul>
    </div>

幻灯片是简单滑块的幻灯片

在我的src'd js文件中的位置,我有这个

$(document).ready(function(){
    $('#show1').click(function(){
      $('#slider').load('slideshow1.html');
    });

    $('#show2').click(function(){
      $('#slider').load('slideshow2.html');
    });
});

,在我的slideshow1.html和slideshow2.html中,我有类似的东西。

<ul>
<li><a href="#"><img src="14.jpg" /></a></li>
<li><a href="#"><img src="15.jpg" /></a></li>
<li><a href="#"><img src="16.jpg" /></a></li>
</ul>

因此,一旦我点击 newslideshows div 中的这些图像链接,滑块 div 就会填充来自 Slideshow1.html 和 Slideshow2.html 的图像,但幻灯片开始显示空白。我猜这是由于简单的滑块功能没有重新启动或类似的原因,有人能想到一个可能的解决方案吗?

谢谢。

So I am trying to populate the slideshow div with images from a external html file but the problem seems to be that the new images do get pulled okay with .load() but the easy slider fails to see the new images and just displays blank even though in the div, there are new image links.

In my html, I have this,

<script type="text/javascript" charset="utf-8">

    $(document).ready(function(){   
    $("#slider").easySlider({
    auto: true, 
    controlsFade: true,
    pause: 3000,
    continuous: false,
    numeric: true
    });
    }); 
    //]]>
    </script>

    <div id="newslideshows">
    <a href="#" id="show1"><img src="image1.jpg" /></a>
    <a href="#" id="show2"><img src="image2.jpg" /></a>
    </div>

        <div id="slider"> 
        <ul>
        <li><a href="#"><img src="1.jpg" /></a></li>
        <li><a href="#"><img src="2.jpg" /></a></li>
        </ul>
    </div>

slide is where the easy slider's slideshow is

in my src'd js file, I have this

$(document).ready(function(){
    $('#show1').click(function(){
      $('#slider').load('slideshow1.html');
    });

    $('#show2').click(function(){
      $('#slider').load('slideshow2.html');
    });
});

and in my slideshow1.html and slideshow2.html, I have something like this.

<ul>
<li><a href="#"><img src="14.jpg" /></a></li>
<li><a href="#"><img src="15.jpg" /></a></li>
<li><a href="#"><img src="16.jpg" /></a></li>
</ul>

So once I hit those image links in the newslideshows div, the slider div gets populated with the images from slideshow1.html and slideshow2.html but the slideshow starts displaying blanks. I am guessing it's due to the easy slider function not being restarted or something in that nature, can anybody think of a possible solution for this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

舂唻埖巳落 2024-10-27 06:26:38

您需要在加载时使用完整的函数,并在其中调用该函数来设置简单的滑块。我猜您在图像加载完成之前正在调用简单滑块。 (很难用您发布的有限代码来说明)

使用 SlideShow 类并在 href 中定义 URL 的新标记。

<div id="newslideshows">
    <a href="slideshow1.html" class="slideShow"><img src="image1.jpg" /></a>
    <a href="slideshow2.html" class="slideShow"><img src="image2.jpg" /></a>
</div>

现在将选择器设置为 SlideShow 类并从href 并使用它加载新的幻灯片:

//you could also use $('#newslideshows a').click(function(evt){
$('.slideShow').click(function(evt){
        //prevent the derault click event
        evt.preventDefault();
        //get the url from the link clicked
        var actionUrl = $(this).attr('href');
        //clear existing ul
        $('#slider ul').remove();
        //call new slideshow
        $('#slider').load(actionUrl), function() {
          //call easy slider here
          $('#slider').easySlider({
          auto: true,
          controlsFade: true,
          pause: 3000,
          continuous: false,
          numeric: true
          });
        });
    });

You need to use the complete function on load and inside it call the function to set easy slider. I am guessing that you are calling easy slider before the images are finished loading. (hard to say with the limited code you posted)

New markup using a class of slideShow and defining the URL in the href.

<div id="newslideshows">
    <a href="slideshow1.html" class="slideShow"><img src="image1.jpg" /></a>
    <a href="slideshow2.html" class="slideShow"><img src="image2.jpg" /></a>
</div>

Now setting the selector as the slideShow class and taking the URL from the href and using it to load the new slide show:

//you could also use $('#newslideshows a').click(function(evt){
$('.slideShow').click(function(evt){
        //prevent the derault click event
        evt.preventDefault();
        //get the url from the link clicked
        var actionUrl = $(this).attr('href');
        //clear existing ul
        $('#slider ul').remove();
        //call new slideshow
        $('#slider').load(actionUrl), function() {
          //call easy slider here
          $('#slider').easySlider({
          auto: true,
          controlsFade: true,
          pause: 3000,
          continuous: false,
          numeric: true
          });
        });
    });
聊慰 2024-10-27 06:26:38

更新: easySlider v 1.7

您需要您的点击功能如下所示。

$('#show1').click(function(){

    //clear out slider's html (the ul)
    //and remove the controls
    $('#slider ul', '#controls').remove();

    //replace slide show html
    $('#slider').load('slideshow1.html'), function() {

      //re-generate controls
      $('#slider').easySlider({
        auto: true,
        controlsFade: true,
        pause: 3000,
        continuous: false,
        numeric: true
      });//easySlider

    });//load success

});//click function

UPDATED: easySlider v 1.7

You need your click functions to look like this.

$('#show1').click(function(){

    //clear out slider's html (the ul)
    //and remove the controls
    $('#slider ul', '#controls').remove();

    //replace slide show html
    $('#slider').load('slideshow1.html'), function() {

      //re-generate controls
      $('#slider').easySlider({
        auto: true,
        controlsFade: true,
        pause: 3000,
        continuous: false,
        numeric: true
      });//easySlider

    });//load success

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