[英]Javascript slideshow to css
in my slideshow its images that slide, but i want it to be divs to run, not images. 在我的幻灯片中,它的图像会滑动,但我希望它是divs运行的,而不是图像。 How i can do it?
我该怎么办?
<img src="img/slide1.png" name="slide" width="100%" height="200" />
<script>
<!--
var image1=new Image()
image1.src="img/slide1.png"
var image2=new Image()
image2.src="img/start.png"
var image3=new Image()
image3.src="img/start1.png"
//variable that will increment through the images
var step=1
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.images.slide.src=eval("image"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 5 seconds
setTimeout("slideit()",5000)
}
slideit()
//-->
</script>
And if its possibly i also wanna to write text into the div class, if you help me, its a really big thanks :D 如果我也想将文本写入div类,如果您帮助我,我真的非常感谢:D
Assuming you are using jQuery in your project, having Divs running as slideshows can be easily accomplished with a jquery plugin like jQuery Cycle 假设您在项目中使用jQuery,可以使用jQuery Cycle这样的jquery插件轻松完成Divs作为幻灯片的运行
An example of rotating divs using jQuery Cycle. 使用jQuery Cycle旋转div的示例 。 Remember to view source.
记住要查看源代码。
The relevant piece of config for jQuery Cycle is: jQuery Cycle的相关配置是:
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.slideshow').cycle({
fx: 'scrollLeft',
pager: '#nav'
});
});
</script>
You can use "delay: -5000" to make it slide every 5 seconds. 您可以使用“延迟:-5000”使其每5秒滑动一次。
You can use setInterval function and changing backgroundImage property for a div will do the task. 您可以使用setInterval函数,并为div更改backgroundImage属性将执行此任务。
<div id="slider-container" style="width:100%;height:200px;"></div>
<script type="text/javascript">
var counter=0;
var no_of_images=3;
var image_name;
setInterval(function(){
image_name=counter%no_of_images;
document.getElementById("slider-container").style.backgroundImage="url(./slide"+image_name+".jpg)";
counter++;
}, 5000);
</script>
You can achieve animations in javascript (if you cannot use jQuery). 您可以使用javascript实现动画 (如果无法使用jQuery)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.