【发布时间】:2016-10-10 12:30:06
【问题描述】:
我在询问一个带有图像、标题和描述 jQuery slide show 的 jQuery 插件。但是找不到这样的。因此尝试仅使用 javascript 构建一个非常小且简单的 [丑陋] 幻灯片。但也有一些缺点,因为在我的脚本中,我必须对图像、标题和描述进行硬编码。所以我想从头开始创建一个 jQuery 插件,它只做与脚本相同的工作,并且还在运行时构建幻灯片。所以这也是一个创建基本幻灯片插件的教程。
我用于简单、丑陋的幻灯片控制器的代码
<html>
<style type="text/css">
td {
border:1px solid #ccc;
width: 420px;
max-width:420px;
text-overflow:ellipsis;
}
span {
word-wrap: break-word;
width: 420px;
max-width:420px;
overflow-y:auto; overflow-x:hidden;
border:1px solid red;
}
</style>
<body>
<table>
<tr><td><img id="img" name="img" src="" title="Image" /></td> </tr>
<tr><td><span id="title">title</span></td></tr>
<tr><td><span id="desc">description</span></td></tr>
<tr><td><input type="button" value="<" onclick="back()" />
<input type="button" value=">" onclick="next()" />
<input type="text" id="idx" value="1" size="2" /> </td></tr>
</table></body>
<script>
var titles = ["zero", "one", "two", "three", "four"];
var descs = ["0 zer0", "1 one ", "2 two ", "3 three", "4 four"];
var img = document.getElementById('img');
var ttl = document.getElementById('title');
var dsc = document.getElementById('desc');
var idx = document.getElementById('idx');
var limit = titles.length-1;
function back()
{
if (parseInt(idx.value) > 1)
idx.value = parseInt(idx.value) - 1;
img.src = 'images/image' + idx.value + '.jpg';
ttl.innerHTML = titles[idx.value];
dsc.innerHTML = descs[idx.value];
}
function next()
{
if (parseInt(idx.value) < limit)
idx.value = parseInt(idx.value) + 1;
img.src = 'images/image' + idx.value + '.jpg';
ttl.innerHTML = titles[idx.value];
dsc.innerHTML = descs[idx.value];
}
</script>
</html>
我希望它被用作
<div id="main">
<img src="...." title="Title of image 1" data-desc="description of #1 image" />
<img src="...." title="Title of image 2" data-desc="description of #2 image" />
</div>
【问题讨论】:
-
你需要更好地解释你的问题。
-
所以你想让别人教你如何重新发明轮子,这样你就可以制作一个关于重新发明轮子的教程?
-
@DelightedD0D,你真是太棒了
-
@Sourav 我猜你正在寻找这样的东西? Simple way of creating jQuery Slider
标签: javascript jquery jquery-plugins slideshow