请帮我解决jquery幻灯片问题

发布于 2024-11-01 18:05:42 字数 761 浏览 6 评论 0原文

我使用 jquery easyslider 创建了一个幻灯片。但它没有发生。我无法找到问题到底出在哪里。

Javascript 如下:

<script type="text/javascript">
    $(document).ready(function(){   
        $("#slider").easySlider({
            auto: true, 
            continuous: true
        });
    }); 
</script>

..以及相应的 HTML:

<div id="slider">
    <ul>                
        <li><img src="Beauty/1.jpg" /></li>
        <li><img src="Beauty/2.jpg" /></li>
        <li><img src="Beauty/3.jpg" /></li>
        <li><img src="Beauty/4.jpg" /></li>
        <li><img src="Beauty/5.png" /></li>         
    </ul>
</div>

I have created a slideshow using jquery easyslider. But its not happening. I am not able to find where exactly the problem.

The Javascript is as follows:

<script type="text/javascript">
    $(document).ready(function(){   
        $("#slider").easySlider({
            auto: true, 
            continuous: true
        });
    }); 
</script>

..and the corresponding HTML:

<div id="slider">
    <ul>                
        <li><img src="Beauty/1.jpg" /></li>
        <li><img src="Beauty/2.jpg" /></li>
        <li><img src="Beauty/3.jpg" /></li>
        <li><img src="Beauty/4.jpg" /></li>
        <li><img src="Beauty/5.png" /></li>         
    </ul>
</div>

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

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

发布评论

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

评论(2

旧竹 2024-11-08 18:05:42

您在此处发布的代码正在运行。我已经设置了一个小提琴: http://jsfiddle.net/jomanlk/jFePh/

看看你的HTML 页面中的代码存在一些问题。

  1. 图像实际上并不存在,所以你不知道它是否正常工作

  2. 你的显示/隐藏代码似乎不起作用(toggleMe('para2') 我认为)。它实际上并没有显示所有容器。

  3. #slider 保持隐藏,内部的 UL 不断在 pt/px 之间切换。

您的标记似乎没问题,但您的 JS 没有按您的预期工作。我猜想 Dreamweaver 已经在页面顶部包含了很多 JS。在向页面添加任何功能之前,您可能需要清理所有内容并让基础知识正常工作。

编辑

您遇到的问题与 easySlider 如何计算尺寸有关。

当 easySlider 代码启动

<div id="para3" style="display:none">

时,它会尝试计算出尺寸。由于高度和宽度设置为 0,因此它实际上无法进行幻灯片放映并放弃(这是一种过度简化),

这可以在我设置的小提琴中看到:http://jsfiddle.net/jomanlk/jFePh/2/

解决方案是删除 < code>display:none 从您的 DIV 中显示,并在 easySlider 加载并完成其功能后使用 JS 隐藏它。

所以要解决这个问题。

  1. 删除 style 属性并添加一个类,使其看起来像这样

  2. 更改顶部的 JS 更改文档顶部的
    $(document).ready(function(){   
        $("#slider").easySlider({
           auto: true, 
           continuous: true
        });
        $('.hideMeLater').hide();//hiding all the divs we removed display:none from
    });
   

应该可以解决您的幻灯片问题。我在这里设置了一个示例: http://jsfiddle.net/jomanlk/jFePh/ 3/

顺便说一句,我建议您熟悉 JS 和 jquery,以便您了解包含插件时实际发生的情况。网上有一些很棒的教程。

另外,您应该清理 HTML。

The code you posted here is working. I've setup a fiddle : http://jsfiddle.net/jomanlk/jFePh/

Looking at your code in the HTML pages there are a couple of problems.

  1. The images don't actually exist so you wouldn't know whether it's working properly anyway

  2. Your show/hide code doesn't seem to be working (toggleMe('para2') I think). It doesn't actually show all the containers.

  3. #slider remains hidden and the UL inside just keeps switching between pt/px.

Your markup seems to be ok, but your JS is not working as you expect. There's a lot of JS that's been included at the top of the page, by Dreamweaver I assume. You might want to clean out all that and get the basics working before you add any functionality to the page.

EDIT

The problem you're having is related to how easySlider figures out the dimensions.

You start out with

<div id="para3" style="display:none">

When the easySlider code kicks in, it tries to figure out the dimensions. Since the height and the width are set to 0 it figures it can't actually do the slideshow and gives up (this is an oversimplification)

This can be seen in this fiddle I setup : http://jsfiddle.net/jomanlk/jFePh/2/

The solution for this would be to remove the display:none from your DIVs and hide it using JS AFTER easySlider has loaded and done its bit.

So to fix this problem.

  1. Remove the style attribute and add a class so it looks like this <div id="para1" class="hideMeLater">

  2. Change the JS at the top of your document so it looks like the below

    $(document).ready(function(){   
        $("#slider").easySlider({
           auto: true, 
           continuous: true
        });
        $('.hideMeLater').hide();//hiding all the divs we removed display:none from
    });
   

This should do fix your slideshow problem. I've set up a fiddle with a sample here : http://jsfiddle.net/jomanlk/jFePh/3/

As an aside, I suggest you get familiar with JS and jquery so that you understand what is actually happening when you include plugins. There are some excellent tutorials available on the net.

Also, you should clean up your HTML.

锦爱 2024-11-08 18:05:42

您有 id="slider" 多个元素尝试提供唯一的 id..
我想然后它会起作用...

you have id="slider" more than one elements try to give unique id..
i think thn it will work...

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