HTML5网页设计

图片效果

jQuery图片上下滚动效果

时间:2014-11-28 17:18来源:未知作者:点击:
实用简洁的图片上下滚动效果,基于jQuery插件来实现的JS特效代码,鼠标移过下边的文字说明会切换至对应的图片,效果流畅。

实用简洁的图片上下滚动效果,基于jQuery插件来实现的JS特效代码,鼠标移过下边的文字说明会切换至对应的图片,效果流畅。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>简单实用的图片上下滚动效果</title>
<script src="http://www.shejicool.com/demo/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
//作者:刘晓帆
$(function(){
    var lxfscroll_ul = $(".lxfscroll ul");
    var lxfscroll_li = $(".lxfscroll li");
    var lxfscroll_tli = $(".lxfscroll-title li");
    var lxfscroll_speed = 350;//切换的速度
    var lxfscroll_autospeed = 2000;//自动播放的速度
    var lxfscroll_n = 0;
    var lxfscroll_imgheight = $(".lxfscroll li img").attr("height");//获取图片高度
    var lxfscroll_lilength = lxfscroll_li.length;//获取图片数量
    var lxfscroll_timer;
    var lxfscroll_alt = $(".lxfscroll-alt");
    /* 标题按钮事件 */
    function lxfscroll() {
        lxfscroll_tli.mouseenter(function(){
            var lxfscroll_index = lxfscroll_tli.index($(this));
            var lxfscroll_lipoint = lxfscroll_index*lxfscroll_imgheight;
            var lxfscroll_imgTitle = $(".lxfscroll li img").eq(lxfscroll_index).attr("alt");
            lxfscroll_alt.text(lxfscroll_imgTitle);
            lxfscroll_tli.removeClass("cur");
            $(this).addClass("cur");
              lxfscroll_ul.stop(true,false).animate({"top":-lxfscroll_lipoint+"px"},lxfscroll_speed);
         });
    };
    /* 自动轮换 */
    function lxfscroll_autoroll() {
    if(lxfscroll_n >= lxfscroll_lilength) {lxfscroll_n = 0;}
        var lxfscroll_lipoint = lxfscroll_n*lxfscroll_imgheight;
        var lxfscroll_imgTitle = $(".lxfscroll li img").eq(lxfscroll_n).attr("alt");
        lxfscroll_ul.stop(true,false).animate({"top":-lxfscroll_lipoint+"px"},lxfscroll_speed);
        lxfscroll_tli.removeClass("cur").eq(lxfscroll_n).addClass("cur");
        lxfscroll_alt.text(lxfscroll_imgTitle);
        lxfscroll_n++;
        lxfscroll_timer = setTimeout(lxfscroll_autoroll, lxfscroll_autospeed);
    };
    /* 鼠标悬停即停止自动轮换 */
    function lxfscroll_stoproll() {
        lxfscroll_li.hover(function() {
            clearTimeout(lxfscroll_timer);
            lxfscroll_n = $(this).prevAll().length+1;
        }, function() {
            lxfscroll_timer = setTimeout(lxfscroll_autoroll, lxfscroll_autospeed);
        });
        lxfscroll_tli.hover(function() {
            clearTimeout(lxfscroll_timer);
            lxfscroll_n = $(this).prevAll().length+1;
        }, function() {
            lxfscroll_timer = setTimeout(lxfscroll_autoroll, lxfscroll_autospeed);
        });
    };
    lxfscroll();
    lxfscroll_autoroll();lxfscroll_stoproll();//启动自动播放功能
});
</script>
<style type="text/css">
*{
    font-size:12px;
    color:#333;
    text-decoration:none;
    padding:0;
    margin:0;
    list-style:none;
    font-style: normal;
    font-family: Arial, Helvetica, sans-serif;
}
.lxfscroll {
    width:400px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 20px;
    position: relative;
    height: 300px;
    border: 4px solid #EFEFEF;
    overflow: hidden;
}
.lxfscroll ul li {
    height: 300px;
    width: 400px;
    text-align: center;
    line-height: 300px;
    font-size: 40px;
    font-weight: bold;
    background-color: #CCC;
    float: left;
}
.lxfscroll-title {
    width: 400px;
    margin-left: auto;
    margin-right: auto;
}
.lxfscroll-title li {
    float: left;
    line-height: 20px;
    text-align: center;
    border: 1px dashed #CCC;
    margin-top: 2px;
    cursor: pointer;
    margin-right: 2px;
    padding: 8px;
}
.cur {
    color: #FFF;
    font-weight: bold;
    background:#000;
}
.lxfscroll ul {
    position: absolute;
}
.lxfscroll-alt {
    position: absolute;
    bottom: 0px;
    z-index: 5;
    background-color: #666;
    width: 384px;
    color: #FFF;
    padding: 8px;Opacity=80);-moz-opacity:0.5;opacity: 0.5;
}
</style>
</head>
<body>
<div class="lxfscroll">
    <div class="lxfscroll-alt">图标文字标题</div>
    <ul>
        <li><img alt="shejicool" height="300" src="http://www.shejicool.com/images/demo/400_1.jpg" width="400" /></li>
        <li><img alt="Lighthouse" height="300" src="http://www.shejicool.com/images/demo/400_2.jpg" width="400" /></li>
        <li><img alt="Penguins" height="300" src="http://www.shejicool.com/images/demo/400_3.jpg" width="400" /></li>
        <li><img alt="Tulips" height="300" src="http://www.shejicool.com/images/demo/400_4.jpg" width="400" /></li>
    </ul>
</div>
<div class="lxfscroll-title">
    <ul>
        <li class="cur">Koala</li>
        <li>Lighthouse</li>
        <li>Penguins</li>
        <li>Tulips</li>
    </ul>
</div>
</body>
</html>
阅完本篇文章?您还可以: 收藏本文 文章挑错 朋友推荐