zoukankan      html  css  js  c++  java
  • 图片轮播 js代码

     1 <script type="text/javascript">
     2     //图片轮换
     3     $(function () {
     4         //------------------
     5         var sWidth = 980; //获取焦点图的宽度(显示面积)
     6         var sHeight = 90; //获取焦点图的高度
     7         var timeInterval = 3000; //获取间隔时间
     8         var len = $("#focus ul li").length; //获取焦点图个数
     9         var index = 0;
    10         var picTimer;
    11         if (len > 1) {
    12             //以下代码添加数字按钮和按钮后的半透明条,还有上一页、下一页两个按钮
    13             var btn = "<div class='btnBg'></div><div class='btn'>";
    14             for (var i = 1; i <= len; i++) {
    15                 btn += "<span>" + i + "</span>";
    16             }
    17             btn += "</div>";
    18             $("#focus").append(btn);
    19             $("#focus .btnBg").css("opacity", 0.5);
    20             //为小按钮添加鼠标滑入事件,以显示相应的内容
    21             $("#focus .btn span").css("opacity", 0.4).mouseenter(function () {
    22                 index = $("#focus .btn span").index(this);
    23                 showPics(index);
    24             }).eq(0).trigger("mouseenter");
    25             //本例为左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度
    26             $("#focus ul").css("width", sWidth * (len));
    27 
    28             //鼠标滑上焦点图时停止自动播放,滑出时开始自动播放
    29             $("#focus").hover(function () {
    30                 clearInterval(picTimer);
    31             }, function () {
    32                 picTimer = setInterval(function () {
    33                     showPics(index);
    34                     index++;
    35                     if (index == len) { index = 0; }
    36                 }, timeInterval); //此4000代表自动播放的间隔,单位:毫秒
    37             }).trigger("mouseleave");
    38         };
    39         //显示图片函数,根据接收的index值显示相应的内容
    40         function showPics(index) { //普通切换
    41             var nowLeft = -index * sWidth; //根据index值计算ul元素的left值
    42             $("#focus ul").stop(true, false).animate({ "left": nowLeft }, 300); //通过animate()调整ul元素滚动到计算出的position
    43             //$("#focus .btn span").removeClass("on").eq(index).addClass("on"); //为当前的按钮切换到选中的效果
    44             $("#focus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300); //为当前的按钮切换到选中的效果
    45         }
    46     })
    47 </script>
    View Code

    @{
        ViewBag.Title = "获取焦点图";
        Layout = null;
        List<AdManage> focusList = ViewData["FocusPic"] as List<AdManage>;
        string AccountUrl = CommonFun.GetAppSettigs("AccountUrl");
    }

    <div id="focus">
            <ul>
                @foreach (var item in focusList)
                {
                    <li><a target="_blank" href="@(item.AdLink)">
                        <img src="@(AccountUrl)/@(item.AdImage)" alt="@(item.AdImageAlt)" title="@item.AdName" width="190" height="70" /></a></li>
                }
            </ul>
        </div>

  • 相关阅读:
    Angular 双向数据绑定
    Angular 过滤器
    Angular 自定义指令传参
    润滑油 标号
    Oracle concat
    sqlldr load UTF8 error
    linux中shell变量$#,$@,$0,$1,$2的含义解释
    shell 执行结果赋给变量
    linux 如何显示一个文件的某几行(中间几行)
    linux shell date 用当天时间做备份文件名
  • 原文地址:https://www.cnblogs.com/huhaihua/p/4108845.html
Copyright © 2011-2022 走看看