【问题标题】:Jquery slideshow image captionJquery幻灯片图片说明
【发布时间】:2013-04-28 21:02:58
【问题描述】:

我正在尝试使段落的文本等于我正在使用此代码和 jquery 的循环插件的图像的 alt 标记。

<html>
<head>
<style type="text/css">.slideshow{height:770px;width:365px;margin:auto}.slideshow    img{padding:10px;border:1px solid #ccc;background-color:#000000}</style>
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">$(document).ready(function(){
///Added ready function to ensure code works on slower browsers
$(document).ready(function(){$('.slideshow').cycle({fx:'fade', pause: 1});});
    $("#test1").text(("#slideshow2").attr("alt"));
  });
});
</script>
</head>
<body>
    <div id="slideshow2" class="slideshow">
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach1.jpg"  width="365" height="770" alt="1"/>
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach2.jpg" width="365" height="770" alt="2"/>
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach3.jpg" width="365" height="770" alt="3"/>
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach4.jpg" width="365" height="770" alt="4"/>
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach5.jpg" width="365" height="770" alt="5"/>
</div>
<p id=test1></p>
</body>
</html>

感谢您,并为我认为这是一个相当愚蠢的问题提前道歉。

【问题讨论】:

    标签: jquery slideshow jquery-cycle caption


    【解决方案1】:

    你可以这样做:

    $(document).ready(function(){
        $('.slideshow').cycle({
            fx:'fade', 
            pause: 1,
            after: function() {
               var altText = $('#slideshow2').find('img:visible').attr('alt');
               $('#test1').text(altText);
            }
        });
    });
    

    【讨论】:

    • 非常感谢我不想要求更多,但你能解释一下为什么会这样吗?我的有什么问题?我想变得更好,而不仅仅是利用别人。
    • 首先你打错了,你忘了在(“#slideshow2”)之前放一个“$”,其次,你尝试取alt attr的部分是错误的,你应该从图像中取它,而不是来自图像持有者。但即使你做对了,它也不会再次起作用。您试图仅获得一次 alt attr,但您需要在每张新幻灯片之后执行此操作,这就是游戏中“之后”回调的地方。因此,在每张幻灯片之后,我们获取当前可见元素的 alt 属性并将其添加到#test1 div。
    • 谢谢。我真的很感激。
    猜你喜欢
    • 2010-11-04
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 2011-01-01
    相关资源
    最近更新 更多