Carousel with dynamic content

点点圈 提交于 2019-12-12 16:25:12

问题


I came across a carousel from Twitter bootstrap here. http://twitter.github.com/bootstrap/javascript.html#carousel

It looks really good. But all the images / content in the example are hard-coded. How can I request the server for new content and show it in the carousel?


回答1:


The answer would have to be adjusted for each language, but assuming you're programing in PHP, it may look something like this:

If you have an array of images:

$images = ['path/to/image.jpg', 'path/to/image2.jpg', 'path/to/image3.jpg']

Then you'd loop through those images, and place each one in the appropriate HTML markup, like so:

<?php foreach ($images as $image) { ?>
  <div class="item">
    <img src="<?php echo $image ?>" />
  </div>
<?php } ?>


来源:https://stackoverflow.com/questions/10232618/carousel-with-dynamic-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!