这篇文章主要介绍了基于Bootstrap框架如何实现图片切换,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
准备图片,把相关记录添加至数据库表中:
创建一个存储过程,获取所有记录:
在ASP.NET MVC专案中,部署Bootstrap环境......
然后创建一个model:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Insus.NET.Models { public class Slider { public byte Slider_nbr { get; set; } public byte Sequence { get; set; } public string Title { get; set; } public string ImageUrl { get; set; } public string Description { get; set; } } }
再创建一个Entity:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Insus.NET.Models; using System.Data; using Insus.NET.ExtendMethods; using Insus.NET.DataBases; namespace Insus.NET.Entities { public class SliderEntity { BizSP sp = new BizSP(); public IEnumerable<Slider> Sliders() { sp.ConnectionString = DB.ConnectionString; sp.Parameters = null; sp.ProcedureName = "usp_Slider_GetAll"; DataTable dt = sp.ExecuteDataSet().Tables[0]; return dt.ToList<Slider>(); } } }
设置图片切换速度:
View视图:
<div class="tp-wrapper"> <div id="imgcarousel" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> @foreach (var item in (new SliderEntity()).Sliders()) { <li data-target="#imgcarousel" data-slide-to="@item.Sequence" class="@(item.Sequence == 0 ? "active" : "")"></li> } </ol> <div class="carousel-inner"> @foreach (var item in (new SliderEntity()).Sliders()) { <div class="@(item.Sequence == 0 ? "item active" : "item")"> <img src="~/Content/img/slider-images/@item.ImageUrl" alt="@item.Description" class="img-responsive" /> <div class="carousel-caption"> <h2>@item.Title</h2> <p>@item.Description</p> </div> </div> } </div> <a class="left carousel-control" href="#imgcarousel" rel="external nofollow" rel="external nofollow" data-slide="prev"> <span class="icon-prev"></span> </a> <a class="right carousel-control" href="#imgcarousel" rel="external nofollow" rel="external nofollow" data-slide="next"> <span class="icon-next"></span> </a> </div> </div>
演示:
感谢你能够认真阅读完这篇文章,希望小编分享的“基于Bootstrap框架如何实现图片切换”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。