colors bright
colors bright

Reputation: 107

image slide show in asp.net mvc3?

I have few images in my database, which im displaying one below the other like a gallery but my requirement is that i want to display like a slide...one image should be displayed and after 2 seconds another image..in that way, how to get it done?

this is my view code

@{
    ViewBag.Title = "Home Page";
}

<h2>@ViewBag.Message</h2>
@for(int i = 1; i <= Convert.ToInt32(ViewData["count"]); i++)
{
    <img src="@Url.Action("dp", "Home",new { id = i })" />
}

Upvotes: 0

Views: 2585

Answers (1)

Coda
Coda

Reputation: 385

You can write something yourself or you can use one of the many JavaScript/jQuery slideshow libraries available. If you write something yourself you will essentially load all of the pictures at once as you're doing but hide them all. Then use JavaScript/jQuery to show them and hide them.

Here is one way using something called jQuery Cycle Plugin from jquery.malsup.com/cycle/.

    @{
        ViewBag.Title = "SlideShow";
    }
    <h2>
        SlideShow</h2>
    <style type="text/css">
        .slideshow
        {
            width: 700px;
            height: 700px;
            margin: auto;
        }
        .slideshow img
        {
            padding: 15px;
            border: 1px solid #ccc;
            background-color: #eee;
            margin-left: auto; margin-right: auto; display: block;
        }
    </style>
    <!-- include Cycle plugin -->
    <script src="@Url.Content("~/Scripts/jquery.cycle.all.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.slideshow').cycle({
                fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            });
        });
    </script>
    <div>
        <a href="javascript:history.go(-1)">Back</a> | @Html.ActionLink("Back to Directory", "Index", new { dir = Request.QueryString["dir"] })
    </div>
    <div class="slideshow">
        @for(int i=1;i<=Convert.ToInt32(ViewData["count"]);i++)
        {
           <img src="@Url.Action("dp", "Home",new { id = i})" />
        }
    </div>

That's the gist anyway... You will have to modify it for your needs.

Upvotes: 1

Related Questions